[英]Add property to entity framework model
I am using Entity Framework in my dataaccess layer, i also use this as my object model. 我在数据访问层中使用实体框架,也将其用作对象模型。
psudo object model: 伪对象模型:
public class Item{
public string ID{get;set;}
public string Name{get;set;}
public Xml Data{get;set;}
}
The Data property is the key here. 数据属性是这里的关键。 i would like to be able to do this:
我希望能够做到这一点:
Psudo: Psudo:
var item = Items.Get(id: 1);
var xmlValue = item["key"];
I would like to be able to extend the EF generated class Item with a new property where i use some logic to get a value by key from the xml. 我希望能够用新属性扩展EF生成的类Item,在该属性中,我使用一些逻辑从xml通过键获取值。
My problem is: 我的问题是:
What is a good way to extend the EF object model? 扩展EF对象模型的好方法是什么?
that i dont 我不
You could just use a partial class and define the extra fields / properties. 您可以只使用局部类并定义额外的字段/属性。
Converting from EF Item to your item is trivial if the fields are the same, you could just use Automapper 如果字段相同,则从EF项转换为项是微不足道的,您可以使用Automapper
i'm leaning towards the partial class solution though. 我倾向于偏类解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.