EF 4:System.Data.Entity.edm.EdmentityType:名称:模式中的每个类型名称必须唯一



我想使用EF代码第一种方法。

我已经阅读了这篇文章:

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

创建我的BL类

public class AppData
{
    public string Id { get; set; }
    public string Url { get; set; }
    public AppData_OptionsDialog OptionsDialog { get; set; }
    public AppData_Compatibility Compatibility { get; set; }
}
public class AppData_Compatibility
{
    public int Id { get; set; }
    public string Platform { get; set; }
    public string MaxVersion { get; set; }
}

public class AppData_OptionsDialog
{
    public int Id { get; set; }
    public string DisplayName { get; set; }
    public string AppDesc { get; set; }
    public string PrivacyPolicyUrl { get; set; }
    public string TermsOfUseUrl { get; set; }
}

public class AppsDataContext : System.Data.Entity.DbContext
{
    public AppsDataContext() : base("MaMDB") { }
    public DbSet<Conduit.Mam.Common.BlData.AppsData.AppData> AppsData { get; set; }
    public DbSet<Conduit.Mam.Common.BlData.AppsData.AppData_Compatibility> AppData_Compatibilities { get; set; }
    public DbSet<Conduit.Mam.Common.BlData.AppsData.AppData_OptionsDialog> AppData_OptionsDialogs { get; set; }       
}

我在DB中创建了Corrisponding表。

我了解EF使用构型而不是配置。

那么它是神奇地将类映射到DB吗?无需生成em

我尝试执行该方法的测试:

    public IList<Conduit.Mam.Common.BlData.AppsData.AppData> GetAll()
    {
        var apps = from app in AppsDataContext.AppsData
               select app;
        return apps.ToList();
    }

,但获取以下错误:

在模型生成过程中检测到一个或多个验证错误:

tsystem.data.entity.edm.edmentitytype:名称:每个类型名称 模式必须是独一无二的。键入名称" appdata_optionsdialog"已经 定义。 tsystem.data.entity.edm.edmentitytype:名称:每个类型名称 在模式中必须是唯一的。键入名称" appdata_compatibility"是 已经定义了。

我已经看到了这个答案,但是它没有帮助我

实体框架错误 - &quot'entityContainer名称必须是唯一的&quot'

我想我知道问题是什么,即使这是非常古老的,我现在遇到了同一问题,似乎EF不喜欢它:

public class User_Roles {
    public bool Admin { get; set; }
    public bool Moderator { get; set; }
    public virtual User User { get; set; }
}
public class User {
    public Guid Id { get; set; }
    public string Username { get; set; }
    public string Salt { get; set; }
    public string Password { get; set; }
    public virtual User_Roles Roles { get; set; }
}

在这种情况下,需要重命名user_roles或需要重命名的用户角色属性,因此:

public class URoles {
    public bool Admin { get; set; }
    public bool Moderator { get; set; }
    public virtual User User { get; set; }
}
public class User {
    public Guid Id { get; set; }
    public string Username { get; set; }
    public string Salt { get; set; }
    public string Password { get; set; }
    public virtual URoles Roles { get; set; }
}

,或者您可以简单地更改用户中的"角色"属性:

public class User_Roles {
    public bool Admin { get; set; }
    public bool Moderator { get; set; }
    public virtual User User { get; set; }
}
public class User {
    public Guid Id { get; set; }
    public string Username { get; set; }
    public string Salt { get; set; }
    public string Password { get; set; }
    public virtual User_Roles URoles { get; set; }
}

在您的情况下,这是在以下情况下发生的:

public AppData_OptionsDialog OptionsDialog { get; set; }
public AppData_Compatibility Compatibility { get; set; }

重命名类,或重命名属性。

最新更新