【问题标题】:non primitive data types for modeling?用于建模的非原始数据类型?
【发布时间】:2013-08-11 12:14:07
【问题描述】:
public class Song
    {
        public int SongID { get; set; }
        public string URL { get; set; }
        public virtual TagLib.Tag SongInfo { get; set; }
    }

我想在我的 Song 实体中使用“TagLib.Tag”数据类型。 当我尝试启用迁移时,我得到:

One or more validation errors were detected during model generation:

\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'XmpNode' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_Exif_Source' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_Exif_Target' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'XmpTag_NodeTree_Source' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_Xmp_Source' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_Xmp_Target' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_OtherTags_Source' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_OtherTags_Target' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_AllTags_Source' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: : The referenced EntitySet 'Tags' for End 'CombinedImageTag_AllTags_Target' could not be found in the containing EntityContainer.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'XmpNodes' is based on type 'XmpNode' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Tags' is based on type 'Tag' that has no keys defined.

如何在我的模型中使用外部复杂数据类型?

【问题讨论】:

  • 请添加 Taglib.Tag 类详细信息

标签: entity-framework asp.net-mvc-4 ef-code-first migration ado.net-entity-data-model


【解决方案1】:

我看到关于 Tag 实体类的错误,您没有为此 Key 属性定义。

也许你的代码如下:

public class Tag
{
    public string TagName{get; set;}
    // other fields
}

你必须改变它如下:

public class Tag
{
    [Key]
    public int TagId{get; set;}
    public string TagName{get; set;}
    // other fields
}

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    相关资源
    最近更新 更多