I ran into a weird problem using CompiledQuery.Compile . When I try to use the readonly static field in the request, I get the following error message:
Class member X is unmapped
If I transfer a field rejection from a partial class to another class not related to LINQ-SQL, then I get the following:
Object reference not set to an instance of an object
If I pass fields through an argument, I see no errors and the query works fine and generates the expected SQL.
An example is as follows:
partial class Order { public static readonly string Complete = "Complete"; public static readonly string Pending = "Pending"; public static readonly Func<DataContext, Order, bool> IsComplete = CompiledQuery.Compile((DataContext context, Order o) => Complete == o.Status); }
Using:
var test = from o in db.Orders select new { IsComplete = Order.IsComplete(db, o) };
This generates errors. If I add string[] as another argument to CompiledQuery , then I see no errors. Also, if I change the lines as const instead of static readonly , this also works, but I suppose this is due to the values ββassigned at compile time.
Is there a way to get static readonly fields?
source share