开发者

Wrapping navigation properties in Entity Framework 4

开发者 https://www.devze.com 2023-03-30 15:30 出处:网络
Say I have a database table Node. The开发者_开发知识库 table contains (among other attributes) the ParentID attribute which is a self-referencing FK.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号