Linq 2个表连接问题
public List<fuction> Getlist(string School)
{
Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext();
IQueryable<fuction> item = from G_info in S_Info.Group_Info1
join G_School in S_Info.Group_SchoolInfo on G_info.Gschool equals G_School.Gschool
where G_info.Gschool.Equals(School)
select new fuction
{
省份 = G_info.Gprovince,
学校 = G_info.Gschool,
班级 = G_info.GroupName,
联系人 = G_School.Contact,
联系邮箱 = G_School.Email,
联系电话 = G_School.Tel
};
return item.ToList();
}
如果联系人为空的话,查询出来的东西,会自动给其它名字,这是什么原因?(如果联系人不为空的话查询出来的东西不会出现这种效果,其它项为空也没有出现这种情况,例如省份为空)求解决方法。求代码指点,Linq菜鸟.
[最优解释]
public List<fuction> Getlist(string School)
{
Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext();
IQueryable<fuction> item = from G_info in S_Info.Group_Info1
join G_School in S_Info.Group_SchoolInfo on G_info.Gschool equals G_School.Gschool
where G_info.Gschool.Equals(School) && (G_School.Contact!=""
[其他解释]
G_School.Contact != null)
select new fuction
{
省份 = G_info.Gprovince,
学校 = G_info.Gschool,
班级 = G_info.GroupName,
联系人 = G_School.Contact,
联系邮箱 = G_School.Email,
联系电话 = G_School.Tel
};
return item.ToList();
}
[其他解释]
public List<fuction> Getlist(string School)
{
Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext();
IQueryable<fuction> item = from G_info in S_Info.Group_Info1
join G_School in S_Info.Group_SchoolInfo on G_info.Gschool equals G_School.Gschool
where G_info.Gschool.Equals(School) && !sting.IsNullOrEmpty(G_School.Contact)
select new fuction
{
省份 = G_info.Gprovince,
学校 = G_info.Gschool,
班级 = G_info.GroupName,
联系人 = G_School.Contact,
联系邮箱 = G_School.Email,
联系电话 = G_School.Tel
};
return item.ToList();
}
[其他解释]
你能把你的问题描述清楚点么
比如原始数据是什么样的
[其他解释]
因为你那2个表没有进行关联,所以造成了笛卡尔现象。表1*表2
------其他解决方案--------------------
看错了不好意思,你的要求是什么,
[其他解释]
如果联系人为空的话,查询出来的东西,会自动给其它名字? 什么名字?
[其他解释]
怎么弄才行,给个代码看看吧
[其他解释]
...错误都在上面了啊,有图有真相的,本来这项没联系人是为空的,但是查询出来的是有的
[其他解释]
上一条记录的名字
[其他解释]
有错误方法“Boolean IsNullOrEmpty(System.String)”不支持转换为 SQL。
[其他解释]
public List<fuction> Getlist(string School)
{
Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext();
IQueryable<fuction> item = from G_info in S_Info.Group_Info1
join G_School in S_Info.Group_SchoolInfo on G_info.Gschool equals G_School.Gschool
where ""!=G_School.Contact
where G_info.Gschool.Equals(School)
select new fuction
{
省份 = G_info.Gprovince,
学校 = G_info.Gschool,
班级 = G_info.GroupName,
联系人 = G_School.Contact,
联系邮箱 = G_School.Email,
联系电话 = G_School.Tel
};
return item.ToList();
}
[其他解释]
你们都理解错我的意思了,你们这些只是判断是否为空,我的意思是,数据库联系人是空的,空的话就输出空的就行,不要限制不给输出(还有一个问题联系人还是有输出的还是上一天记录的联系人(本来这条记录是联系人是为空的))
[其他解释]
人都跑哪去了..
[其他解释]
求解答啊
[其他解释]
...还不清楚吗?
这就是原始数据,只是联系人那一项是为空的,现在查询出来却是上一条记录的联系人
[其他解释]
来牛人啊
[其他解释]
这就是我要显示的东西,也就是数据库里面的数据,联系人这一项为空的