Rajat Suneja
Rajat Suneja

Reputation: 552

ASP.Net Linq getting Column Names and Data

I am trying to create a system as follows -

  1. UI layer - dropdowns with options to filter the data to be shown

  2. Mid layer - ".cs" classes to manipulate the data

  3. Back Layer - here the data gets filtered and returned into classes (EDMX file and classes)

However my implementation is not working... the error is shown as "Reference for different contexts"..

protected void Page_Load(object sender, EventArgs e)
{
    inc = (IQueryable<Incident_Raw_Data>)Session["INC"];
    AppInfo = (IQueryable<Application_Info>)DbData.GetDBData().AppInfo;
    RespConfg = (IQueryable<Response_Config>)DbData.GetDBData().RespConfig;
    ResolConfg = (IQueryable<Resolution_Config>)DbData.GetDBData().ResolConfig;

    DTbl = QueryRslt(xyz, abc);
    Data = GetData();
    Cols = Col();
}

Never mind any return statements missing ;;

public DataTable QueryRslt(string Type, string Value)
{
    if (!string.IsNullOrEmpty(Type))
    {
        var str = (from IR in inc
                   join AI in AppInfo on IR.CI equals AI.Application_Name
                   join RC in RespConfg on AI.Service_Level_Categoty equals RC.Category
                   where (RC.Tkt_Type == "Incident" && IR.Priority == Value)
                   select new
                   {
                       ID = IR.Incident_ID,
                       CI = IR.CI,
                       Status = IR.Status,
                       BenchMark_Response_Time = RC.Days_Benchmark,
                       SLMDeviation = ((EntityFunctions.DiffHours(IR.Incident_Reported_Date, IR.Incident_Responded_Date) / 24.0) - RC.Days_Benchmark),
                       Priority = IR.Priority,
                       ReportedDate = IR.Incident_Reported_Date,
                       RespondDate = IR.Incident_Responded_Date,
                       AssigneeGroup = IR.Assignee,
                       AssignedGroup = IR.Assigned_Group
                   }).ToList();
    }
}

Upvotes: 1

Views: 223

Answers (1)

Andreas Johansson
Andreas Johansson

Reputation: 172

It looks like you are trying to joins different data contexts. That is not supported.

You should also instanciate the data context object when you need it and not store it in the session, as i guess you are dooing with the "INC".

inc, APPInfo and RestConf must not be collected from different instances of the data context.

Upvotes: 2

Related Questions