CTP5:还是自我引用问题? [英] CTP5: still self-reference issue?
问题描述
有一个简单的模型:
公共类节点
{
public long Id {get;组; }
public virtual Node Parent {get;组; }
}
public class Node
{
public long Id { get; set; }
public virtual Node Parent { get; set; }
}
以下地图代码将引发异常:
the following map code will throw an exception:
public class NodeContext:DbContext
{
public DbSet< Node>节点{get;组; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
public class NodeContext : DbContext
{
public DbSet<Node> Nodes { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity< Node>()。HasOptional(n => n.Parent).WithMany()。IsIndependent()。Map(m => m.MapKey(p => p.Id," ParentId" ));
modelBuilder.Entity<Node>().HasOptional(n => n.Parent).WithMany().IsIndependent().Map(m => m.MapKey(p => p.Id, "ParentId"));
}
}
}
}
可能是因为它无法自我引用自定义外键名称吗?是吗?
推荐答案
我有类似的东西
刚丢失
。地图(m => m.MapKey(p => p.Id," ParentId")))
部分
...建筑似乎有一些问题,所以我认为它确实没有用。
你可能会得到NodeId而不是parentId,没关系多少b $ b希望它有帮助
Gaga
I have something similar
just lose the
.Map(m => m.MapKey(p => p.Id, "ParentId"))
part
...that construction seems to have some problems, so I don't think it works really.
You'll probably get NodeId instead of parentId, doesn't matter much
hope it helps
Gaga
这篇关于CTP5:还是自我引用问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!