Alf*_*ono 1 entity-framework-4
我有一个与此类似的实体框架模型:
我可以添加,查询(使用OfType)和更新员工和联系人没有问题.但是,我无法确定Person对象的类型.比如说:
var person = entities.People.Single(p => p.Id == 5);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点:
if (person.IsEmployee){
//do something
} else if (person.IsContact) {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
或者,我可以满足于此:
if (person.IsOfType<Employee>()){
// do something
} else if (person.IsOfType<Contact>()) {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
有办法吗?
Cra*_*ntz 12
if (person is Employee){
//do something
} else if (person is Contact) {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1384 次 |
| 最近记录: |