EF 4.2 Много-много багов? - PullRequest
       11

EF 4.2 Много-много багов?

1 голос
/ 22 декабря 2011

Мы используем членство в ASP.NET для управления нашим пользователем, и я обнаружил проблему с использованием Entity Framework 4.2

У меня есть таблица в db с именем Aspnet_Users, и я создал свой класс как:

public class Aspnet_User
{
    [Key]
    public Guid ID { get; set; }
    public Guid ApplicationID { get; set; }
    public string UserName { get; set; }
    public string LoweredUserName { get; set; }
    public string MobileAlias { get; set; }
    public bool IsAnonymous { get; set; }
    public DateTime LastActivityDate { get; set; }

    public virtual Aspnet_Membership Aspnet_Membership { get; set; }
    public virtual Aspnet_Profile Aspnet_Profile { get; set; }

    public virtual ICollection<Aspnet_Role> Aspnet_Roles { get; set; }
    public virtual ICollection<Agent> Agents { get; set; }
}

Конфигурация моей сущности:

public class Aspnet_UserConfiguration : EntityTypeConfiguration<Aspnet_User>
{
    public Aspnet_UserConfiguration()
        : base()
    {
        HasKey(p => p.ID);

        Property(p => p.ID).HasColumnName("UserId").IsRequired();

        Property(p => p.MobileAlias).IsOptional();

        HasOptional(p => p.Aspnet_Profile).WithRequired();
        HasOptional(p => p.Aspnet_Membership).WithRequired();

        HasMany(p => p.Aspnet_Roles).WithMany(a => a.Aspnet_Users).Map(mc =>
            {
                mc.MapLeftKey("UserId");
                mc.MapRightKey("RoleId");
                ToTable("aspnet_UsersInRoles");
            });

        HasMany(p => p.Agents).WithMany(a => a.Aspnet_Users).Map(mc =>
            {
                mc.MapLeftKey("UserId");
                mc.MapRightKey("AgentId");
                ToTable("aspnet_UsersAgent");
            });

        ToTable("aspnet_Users");
    }

И, наконец, таблица моего агента:

public class Agent
{
    [Key]
    public int ID { get; set; }
    public string Title { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public string ShortBio { get; set; }
    public string ExtendedBio { get; set; }
    public string Tel { get; set; }
    public string Fax { get; set; }
    public string Email { get; set; }
    public string CompanyName { get; set; }
    public string ImageURL { get; set; }
    public string BranchName { get; set; }
    public string UserPassword { get; set; }
    public DateTime? LastLogin { get; set; }
    public bool? Active { get; set; }
    public bool ShowMap { get; set; }
    public string BatchNoPrefix { get; set; }

    public string FullName
    {
        get { return string.Format("{0} {1}", FirstName, Surname); }
    }

    public virtual AgentsAddress Address { get; set; }

    public virtual ICollection<PaymentNotification> PaymentNotifications { get; set; }
    public virtual ICollection<Authority> Authorities { get; set; }
    public virtual ICollection<Aspnet_Users> Aspnet_Users { get; set; }
}

Проблема: Когда я пытаюсь выбрать Aspnet_User в классе Agent, я получаю сообщение об ошибке:

Invalid object name 'dbo.Aspnet_UserAgent'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Aspnet_UserAgent'.

Я понял, что эта ошибка возникает, потому что мое имя класса в единственном числе: Aspnet_User вместо Aspnet_Users.

Но если я создал отношение внутри своей Конфигурации (см. Класс aspnet_UserConfiguration), система не должна пытаться получить aspnet_UsersAgent? Почему он пытается получить dbo.ClassName1_ClassName2? Это ошибка?

Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...