具有多个条件的多个联接

时间:2015-04-29 13:24:26

标签: c# linq

我试图列出具有各自国家和地区的城市的网格视图,其状态为真 这里的层次结构是Country - > Area - > City 这是我的代码。
不知何故,它显示连接错误: -

  

join子句中某个表达式的类型是wrong.Type   推理无法调用Join

我缺少什么?

protected void Fn_fill_city()
{
    EF_DV.DBEntities City_Context = new EF_DV.DBEntities();
    try
    {
        var row_city = 
            (from city_table in City_Context.DV_Tbl_City
            join country_table in City_Context.DV_Tbl_Country 
                 on new { 
                    C_Id = city_table.City_Country_Id, 
                    c_status = true 
                 } 
                 equals new {
                    C_Id = country_table.Country_Id, 
                    c_status = country_table.Country_Status 
                 }
            join area_table in City_Context.DV_Tbl_Area 
                 on new { 
                    area_Id = city_table.City_Area_Id, 
                    a_status = true 
                 } 
                 equals new { 
                    area_Id = area_table.Area_Id, 
                    a_status = area_table.Area_Status 
                 }
            orderby city_table.City_Name
            where (                                   
                   (city_table.City_Name.Contains(Txt_search_city.Text.Trim()) ||
                   (Txt_search_city.Text.Trim() == ""))
                  )
            select new
            {
                city_table.City_Id,
                city_table.City_Name,
                city_table.City_Status,
                city_table.City_Code,
                country_table.Country_Name,
                area_table.Area_Name
            }).ToList();
        gv_city.DataSource = row_city;
        gv_city.DataBind();
        gv_city.HeaderRow.TableSection = TableRowSection.TableHeader;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        City_Context = null;
    }
}

1 个答案:

答案 0 :(得分:0)

db驱动程序可能不支持Trim()操作...... 只是尝试删除Trim()