var list =
from a in TableA
select new B {
Count = a.TotalCount
, Title = a.Title
};
You new up an instance of B in your select clause, and assign the properties using the inline property assignment feature in C# 3.0.
The advantages of mapping it inline comes from deferred execution of your Linq statement. Linq will map the modified statement, and execute it from your IQueryable. For example:
public class ClassA
{
public int TotalCount;
public string Title;
}
public class ClassB
{
public int Count;
public string Title;
}
public IQueryable<ClassB> FetchAllOfClassB()
{
var list =
from a in TableOfClassA
select new ClassB {
Count = a.TotalCount
, Title = a.Title
};
return list.AsQueryable();
}
Technically, the AsQueryable is a bit redundant. Sometimes I use to to make it a point, others say it is absolutely required. None the less, the list object itself is IQueryable of ClassB.
Then you can call FetchAllOfClassB() further up the chain, and use IQuerable. It's pretty slick, and efficient.