Qasim Ali 0 Newbie Poster

Dear Sir

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<Definition> defintions = (from d in data.Definitions.Include("Versions") where d.Category.ID == cat.ID select d).ToList();

IList<DynamicForms.Data.Version> versions;
if (defintions.Count>0)
{
versions = defintions.SelectMany(d=>d.Versions).ToList();
Grid.DataSource = versions;
Grid.DataBind();
}

If I have to use sub query then How I can implement and use sub query in this code please.
Your early reply will be highly appriciated.