如何检索基类(实体框架)? [英] How to retrieve base class only (entity framework)?
本文介绍了如何检索基类(实体框架)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Consumer类和一个BillableConsumer类继承了Consumer。他们都是消费者的一部分。问题是,以下查询:
Consumer consumer =(from c in _ctx.Consumers where c.ID = id select c )。第一();
返回一个BillableConsumer实例!与这个查询一样:
BillableConsumer bconsumer =(从_ctx.Consumers.OfType< BillableConsumer>()中的c)其中c .ID = id select c).First();
如何返回只有基类的实例? (这些是数据存储中的单独表格)。
解决方案
是的,这有点棘手。
但是我做了一个提示在这一段时间后
希望这有助于
Alex
I've been scratching my head here for a while now... I have a Consumer class and a BillableConsumer class that inherits Consumer. They are both a part of the Consumers set. The problem is that this following query:
Consumer consumer = (from c in _ctx.Consumers where c.ID = id select c).First();
returns a BillableConsumer instance! Just the same as this query:
BillableConsumer bconsumer = (from c in _ctx.Consumers.OfType<BillableConsumer>() where c.ID = id select c).First();
How can I return an instance of just the base class? (these are separate tables in the data store).
解决方案
Yes this is a little tricky.
But I did a tip on this a while back
Hope this helps
Alex
这篇关于如何检索基类(实体框架)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文