2

FileDownloadContentModel拡張するクラスがありますIBaseContentModel

 public class FileDownloadContentModel : IBaseContentModel
 {

    public string url { get; set; }
    public string filename { get; set; }
    public int downloadPercentage { get; set; }
    public DateTime dateDownloaded { get; set; }
    public byte[] content { get; set; }
 }

ここにあるIBaseContentModel

 public class IBaseContentModel
 {
    [PrimaryKey]
    public int id { get; set; }

    public IBaseContentModel()
    {
        id = GenerateID();
    }

    protected static int GenerateID()
    {
        DateTime value = DateTime.UtcNow;
        //create Timespan by subtracting the value provided from the Unix Epoch
        TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
        //return the total seconds (which is a UNIX timestamp)
        return (int)span.TotalSeconds;
    }
 }

何らかの理由で、sqlite-net はテーブル マッピングを取得するときに主キーを認識できません。主キーがnullであることを示しています。FileDownloadContentModelクラスにID(主キー)を直接含めると、主キーをIDとして認識できます。

これは既知のバグですか、それともここで何か間違ったことをしていますか? どんな助けでも大歓迎です、ありがとう!

更新しました

私は今それをもっと調べましたが、それは私の愚かな間違いです. sqlite の 2 つの「インスタンス」があり、何らかの理由で IBaseContentModel が FileDownloadContentModel とは異なる sqlite のインスタンスを使用していたため、主キーが認識されませんでした (同じインスタンスからのものではないため)。たとえば、パッケージ名が異なる 2 つの完全に異なる sqlite.cs ファイルを意味します。

4

1 に答える 1

0

.NET の正常な動作のようです。インターフェイスは実際には継承されません。そのコントラクトを実装することを強制するだけです。実装はスタンドアロンであり、インターフェイスから何も継承しません。
そのため、次のテストは失敗します。

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;

namespace TestProject2
{
    public interface IMyInterface
    {
        [Description("Test Attribute")]
        void Member();
    }

    [TestClass]
    public class Class1 : IMyInterface
    {
        public void Member()
        {

        }

        [TestMethod]
        public void TestAttributeInheritance()
        {
            Console.WriteLine("Checking interface attribute");
            MethodInfo info = typeof(IMyInterface).GetMethod("Member");
            Assert.AreEqual(1, info.GetCustomAttributes(typeof(DescriptionAttribute), true).Length);

            Console.WriteLine("Checking implementation attribute");
            info = typeof(Class1).GetMethod("Member");
            Assert.AreEqual(1, info.GetCustomAttributes(typeof(DescriptionAttribute), true).Length);
        }
    }
}

結果:

Checking interface attribute  
Checking implementation attribute  
Assert.AreEqual failed. Expected:<1>. Actual:<0>.
于 2013-08-05T22:28:54.470 に答える