المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How I can filter out Child Entities



C# Programming
06-09-2009, 05:40 PM
Dear Sir/madom

I have three tables

1. Categorys (ID, Name)
2. Definitions (ID, Name, CategoryID)
3. Versions( ID, Name, DefinitionID)

I have generated three objects using EDM
1 Cagegorys
Navigation (Definition)
2. Definitions
Navigation (Category, Version)
3. Versions
Navigation (Definition)


I want to get latest versions against each category

My Code is as follow It return all version against the categoryId but I want to get only latest version of each definition against a category.


DataEntities data = new DataEntities();

Category cat = (from c in data.Categorys where c.ID == CategoryID select c).First();

IList defintions = (from d in data.Definitions.Include("Versions") where d.Category.ID == cat.ID select d).ToList();

IList versions;

if (defintions.Count>0)

{

versions = defintions.SelectMany(d=>d.Versions).ToList();


Grid.DataSource = versions;

Grid.DataBind();

}

If I need sub query How I have construct and use subquery in this code

Your early reply will be highly appriciated please.