我在我的项目中使用以下模型。但是我正在尝试获得下面给出的sql的相同linq查询。我想要的结果,部门id和部门名称有链接到用户。此外,如果该部门针对其仓库和部门存在,则默认部门标志设置为true
public class UserDepartmentLink
{
public int Depotno { get; set; }
public int Departmentid { get; set; }
public int Userid { get; set; }
public bool Isdeleted { get; set; }
[not mapped]
public bool IsDefault { get; set; }
}
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public int depotno { get; set; }
public int departmentid { get; set; }
}
public class Department
{
public int departmentid { get; set; }
public string DepartmentName { get; set; }
}
int[] depot =(1,2,3)
select distinct A.DepartmentName
,a.DepartmentID
,case when Exists(Select *
from goUser c join goUserDepartmentLink d
on c.DepotNo=d.DepotNo
and c.DepartmentID=d.DepartmentID
and d.DepotNo in(depot)
where c.DepartmentID= B.DepartmentID
and c.UserID=5)
then 1 else 0 End as Selected
from Department A
inner join UserDepartmentLink B on A.DepartmentID = B.DepartmentID
Where B.UserID= 5
and B.DepotNo in(depot)
and B.IsDeleted=0;
我想将linq结果存储到新的模型类userdepotdepartment中
select new GoUserDepartLink
{
DepartmentID = A.DepartmentID,
DepartmentName = A.DepartmentName,
IsDefault = false
}
暂无答案!
目前还没有任何答案,快来回答吧!