相关疑难解决方法(0)

实体框架4.1代码第一外键ID

我有两个实体引用了一对多.当实体框架创建表时,它会创建两个外键,一个用于我用Fluent接口指定的键,另一个用于ICollection.如何摆脱重复的外键?

public class Person
{
    public long RecordId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string Username { get; set; }

    public long DepartmentId { get; set; }
    public virtual Department Department { get; set; }
}

public class Department
{
    public long RecordId { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Person> People { get; …
Run Code Online (Sandbox Code Playgroud)

c# poco entity-framework-4.1

19
推荐指数
2
解决办法
3万
查看次数

映射仅在一侧需要导航属性的关系

我有这个型号:

public class Blog
{
    public int ID { get; set; }
    public string Title { get; set; }
}

public class Post
{
    public int ID { get; set; }
    public string Title { get; set; }
    public string Content { get; set; } 
    public int BlogID { get; set; }
    public Blog Blog { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

有这个配置:

public class BlogMap : EntityTypeConfiguration<Blog>
{
    public BlogMap()
    {
        this.ToTable("Blogs", "dbo");
        this.HasKey(t => t.ID);
        this.Property(t => t.ID).HasColumnName("ID");
        this.Property(t => …
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-6

0
推荐指数
1
解决办法
509
查看次数