Map model object to DataConext

124 Views Asked by At

Below is the code I'm trying to use for my first attempt at a compiled linq query. The code builds fine and the site will run as it's expected to, however once the program calls the compiled method I recieve the error: The type 'Monet.Models.ZipCodeTerritory' is not mapped as a Table.

I can't seem to find anything on the net that speaks to this specific issue. Can someone tell me what I need to do to map the ZipCodeTerritory table to the DataContext object? I'm using the Entity Framework and ZipCodeTerritory is the model being used on this page.

Parameters/Constructor

private static Func<DataContext, ZipCodeTerritory, List<ZipCodeTerritory>> SearchEffectiveDate;
private static DataContext _dbContext;
public ZipCodeValidatorCompiled()
{
    _dbContext = new DataContext(ConfigurationManager.AppSettings.Get("db"));
    SearchEffectiveDate = CompiledQuery.Compile((DataContext db, ZipCodeTerritory zipCode)
    =>
    from z in db.GetTable<ZipCodeTerritory>()
    where z.DrmTerrDesc.Equals(zipCode.DrmTerrDesc) &&
            z.IndDistrnId.Equals(zipCode.IndDistrnId) &&
            z.StateCode.Equals(zipCode.StateCode) &&
            (z.ZipCode.Equals(null) ? z.ZipCode.Equals(null) : z.ZipCode.Equals(zipCode.ZipCode))
    select z
    );
}

Compiled Method Call

List<ZipCodeTerritory> terrList = SearchEffectiveDate(_dbContext, zipCode); //Error thrown here

EDIT

I updated the parameters and constructor like so. Now I am trying to create a instance of the ZipCodeTerritory table on its own and then use that in the precompiled query. However, I receive the exact same message on this line in the constructor: ZipCode = _dbContext.GetTable<ZipCodeTerritory>();

Parameters/Constructor

private static DataContext _dbContext;
private static Table<ZipCodeTerritory> ZipCode; //New

public ZipCodeValidatorCompiled()
{
    _dbContext = new DataContext(ConfigurationManager.AppSettings.Get("db"));
    ZipCode = _dbContext.GetTable<ZipCodeTerritory>(); //New

    SearchEffectiveDate = CompiledQuery.Compile((DataContext db, ZipCodeTerritory zipCode)
    =>
    (from z in ZipCode //New
    where z.DrmTerrDesc.Equals(zipCode.DrmTerrDesc) &&
            z.IndDistrnId.Equals(zipCode.IndDistrnId) &&
            z.StateCode.Equals(zipCode.StateCode) &&
            (z.ZipCode.Equals(null) ? z.ZipCode.Equals(null) : z.ZipCode.Equals(zipCode.ZipCode))
    select z).ToList()
    );
}
0

There are 0 best solutions below