相关疑难解决方法(0)

EF4 Code First:如何在不添加导航属性的情况下添加关系

我应该如何使用Code First定义关系但不使用任何导航属性?

以前我通过在关系的两端使用导航属性来定义One-Many和Many-Many.并在数据库中创建适当的关系.这里是类的外观的简化版本(为了简单起见,我将Many-Many关系转换为one-many).

public class User 
{
    public string UserId { get; set; }
    public string PasswordHash { get; set; }
    public bool IsDisabled { get; set; }
    public DateTime AccessExpiryDate { get; set; }
    public bool MustChangePassword { get; set; }

    public virtual Role Role { get; set; }
}

public class Role
{
    public int RoleId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }

    public virtual ICollection<User> Users …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework code-first entity-framework-4 ef-code-first

15
推荐指数
1
解决办法
8387
查看次数