EF Compile Query and Configurable Constraints

38 Views Asked by At

I have been looking into this, and I haven't been able to find an answer.

We are using EF 6.0 in C#, I was hoping to use the EF Compiled query to avoid some Dynamic SQL.

We have a set of Constraint defined to find recommendable data. and Those conditions can change between networks.

For instance AZNEtwork Network Id is AZNETWORK Speciality Code is PEDS Age is less than 21

For CANETWORK Network Id is AZNETWORK Speciality Code is PEDS Age is less than 18

We currently deal with this in Dynamic SQL, I was hoping to handle this in EF Queries. I know how to add constraints to an IQueryable with extensions. Is it possible to compile a EF Query with the configured constraints.

public static IQueryable<ProvData> azFunction(preprodContext ctx, string networkId, 
string specCode, int age)
{
   var azquery = from    load in ctx.ProvTable
                 select  new ProvData
                             {
                               Id        =   load.Id,
                               NetworkId =   load.NetworkId,
                               SpecCode  =   load.SpecCode,
                               Age       =   load.Age
                             });
  azQuery = azQuery.Where(x = x.NetworkId == networkId);
  azQuery = azQuery.Where(x = x.SpecCode  == specCode);
  azQuery = azQuery.Where(x = x.Age       == age);
  return(azQuery);
}

And then one for CA

private static Func<preprodContext, string, string, int, IAsyncEnumerable<Prov>> azCompiled =
   EF.CompileAsyncQuery((preprodContext ctx, string networkId, string specCode, int age ) =>
      azFunction(ctx, networkId, specCode, age);

From every example tat I have found defines the query in the same statement that is compiling it.

Is this Possible

Thanks

M. Daly

0

There are 0 best solutions below