I'm new to LINQ, but I have some background in T-SQL. I know there are probably 100 different ways to design a T-SQL statement that would run this much more efficiently, but I'm not sure how I would do it in LINQ and I would like to stick with LINQ.
This works perfectly well, I just hate the way it looks and am unsure of how to fix it.
I am using MVC3, C#, LINQ, Entity Framework 4.3
public class CollectionRepository : ICollectionRepository {
private CollectionEntities db = new CollectionEntities();
public IEnumerable<Collection> GetCollectionByUid(long id) {
var _collection = (from c in db.UserCollections
where c.uid == id
orderby c.CreateDate descending
select new Collection {
Name = c.CollectionName,
Type = (from t in db.CollectionTypes
where t.ctypeid == c.Type
select t.CollectionTypeName).FirstOrDefault(),
Created = c.CreateDate,
Count = (from f in db.Figures
where f.CollectionID == c.cid
select f).Count()
}).ToList();
return _collection;
}
}
The constructors it points to:
public class Collection {
public string Name { get; set; }
public string Type { get; set; }
public DateTime Created { get; set; }
public int Count { get; set; }
}