Reputation:
Say I have the following generated Entity Framework POCO class:
public partial class Foo
{
#region Primitive Properties
public virtual long Id { get; set; }
#endregion
}
And I subclass it:
public class SubclassedFoo : Foo
{
public override long Id
{
get { return base.Id; }
set { base.Id = value; }
}
}
How can the ObjectContext retrieve SubclassedFoo
objects rather than Foo
objects?
For example, what can I use instead of this?
ObservableCollection<Foo> foos = context.Foos
as in:
ObservableCollection<SubclassedFoo> subclassedFoos = context.???
Upvotes: 2
Views: 91
Reputation: 177133
Filter with OfType<SubclassedFoo>
:
List<SubclassedFoo> subclassedFoos = context.Foos
.OfType<SubclassedFoo>()
.ToList();
Or if you really want an ObservableCollection
:
ObservableCollection<SubclassedFoo> subclassedFoos =
new ObservableCollection<SubclassedFoo>(context.Foos
.OfType<SubclassedFoo>()
.AsEnumerable());
Upvotes: 1