如何使用像int这样的复杂类型来查询数据库?
我有一个看起来像这样的表:
ID | Name
----+-------
1 | Foo
2 | Bar
我有一个看起来像这样的实体:
[Table("MyEntityTable")]
public class MyEntity{
[Column("ID")]
public CustomId ID {get;set;}
[Column("Name")]
public string Name {get;set;}
}
public class CustomId {
public int ID => GetId();
public object SomeObject {get;set;}
public CustomId(object o){
SomeObject = o;
}
private int GetId() => //logic returns a unique ID that maps to database column.
}
如何告诉实体框架当某些内容为CustomId
时,它应该只将int
部分映射到指定的列并忽略其余部分?
所以我可以这样做:
var id = new CustomId(myObject);
var entity = db.MyEntitys.First(e => e.ID == id);