Hi,
I'm trying to pre-fetch some foreign key data using a linq query. A quick example to explain my problem follows:
var results = (from c in _customers
from ct in _customerTypes
where c.TypeId == ct.TypeId
select new Customer
{
CustomerId = c.CustomerId,
Name = c.Name,
TypeId = c.TypeId,
TypeName = ct.TypeName, <-- Trying to Prefetch this
}).ToList();
The Customer class looks like:
[Table(Name = "Customers")]
public class Customer
{
[Column(Name = "CustomerId", IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public int CustomerId { get; set; }
[Column(Name = "Name")]
public string Name { get; set; }
[Column(Name = "TypeId")]
public int TypeId { get; set;}
public string TypeName { get; set; }
public Confession (){}
}
However LINQ will not let you do this throwing a NotSupportedException with "Explicit construction of entity type 'Customer' in query is not allowed."
I'm clearly approaching this incorrectly. Any pointers in the right direction would be most helpfull.