在 Entity Framework 4 中包装导航属性
假设我有一个数据库表Node
。
该表包含(以及其他属性)ParentID
属性,它是一个自引用 FK。
从此类数据库表创建的实体框架模型包含两个导航属性:
EntityCollection
; Node1 Node Node2
名称很混乱,所以我在设计器中更改了名称。
这种方法的问题是设计者在更新同一个类时会覆盖我的更改。
我想要做的是创建部分类(在另一个文件中),这些类基本上会包装提到的导航属性:
public EntityCollection<Node> ChildrenNodes
{
get
{
return Node1;
}
set
{
Node1 = value;
}
}
public Node ParentNode
{
get
{
return Node2;
}
set
{
Node2 = value;
}
}
现在,我可以从头开始重新创建 EDMX,并且我的属性将保留。
但是,我不确定这是否会破坏实体框架。我不知道有多少 EF 通过该名称进行访问,因此我不确定此类操作会产生什么后果。
这会正常工作还是会产生一些问题?
Say I have a database table Node
.
The table contains (among other attributes) the ParentID
attribute which is a self-referencing FK.
Entity Framework model created from such database table contains two navigational properties:
EntityCollection<Node> Node1
Node Node2
The names are confusing so I changed the names in the designer.
The problem with the approach is that the designer will overwrite my changes when updating the same class.
What I'd like to do is create the partial classes (in another file) that would basically wrap the mentioned navigation properties:
public EntityCollection<Node> ChildrenNodes
{
get
{
return Node1;
}
set
{
Node1 = value;
}
}
public Node ParentNode
{
get
{
return Node2;
}
set
{
Node2 = value;
}
}
Now, I can recreate the EDMX from scratch and my properties will remain.
However, what I am not sure about is whether this will break the Entity Framework. I don't know how much EF accesses by the name, so I am not sure what would be the consequences of such action.
Would this work normally or would it create some problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论