views:

604

answers:

1
+1  A: 

If you want to work with them based on their concrete type - that sounds like a case for polymorphism... can you (in a partial class) add a few methods?

partial class Paragraph {
    public abstract void Foo();
}
partial class ImageParagraph {
    public override void Foo() {/*code*/}
}
partial class LinkListParagraph {
    public override void Foo() {/*code*/}
}

Otherwise, if you want to filter the set, you can use the OfType extension method - i.e.

foreach(var imgPara in obj.Paragraphs.OfType<ImageParagraph>())
{ ... }

Perhaps you could add properties for the above too (in the parent object) - i.e.

partial class Site {
    public IQueryable<ImageParagraph> ImageParagraphs
    { get {return Paragraphs.OfType<ImageParagraph>(); }}

    public IQueryable<LinkListParagraph> LinkListParagraphs
    { get {return Paragraphs.OfType<LinkListParagraph>(); }}
}
Marc Gravell
Thanks.My question was unclear.I want to do: var site =context.Site.Include("Paragraphs").Where(c => c.SiteID == 1).First(); foreach(var paragraph in site.Paragraphs) { do something }; My problem is that I do not know the mapping in the EDM.(like with Table per Hierarchy with conditions)
chbu