I am trying to pre-get some foreign key data using linq query. The following is a brief example of an explanation of my problem:
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 this:
[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 allow you to throw this NotSupportedException with "Explicitly building the type of the Client object in the request is not allowed."
I am clearly approaching this wrong. Any pointers in the right direction would be most helpful.
Magpie
source share