说我有以下生成的Entity Framework POCO类:
public partial class Foo
{
#region Primitive Properties
public virtual long Id { get; set; }
#endregion
}
我将其子类化:
public class SubclassedFoo : Foo
{
public override long Id
{
get { return base.Id; }
set { base.Id = value; }
}
}
ObjectContext如何检索SubclassedFoo
个对象而不是Foo
个对象?
例如,我可以用什么代替呢?
ObservableCollection<Foo> foos = context.Foos
如:
ObservableCollection<SubclassedFoo> subclassedFoos = context.???
答案 0 :(得分:1)
使用OfType<SubclassedFoo>
过滤:
List<SubclassedFoo> subclassedFoos = context.Foos
.OfType<SubclassedFoo>()
.ToList();
或者如果你真的想要一个ObservableCollection
:
ObservableCollection<SubclassedFoo> subclassedFoos =
new ObservableCollection<SubclassedFoo>(context.Foos
.OfType<SubclassedFoo>()
.AsEnumerable());