Closed quan01994 closed 6 years ago
use ef it's run , but ef generate two sql to exec and ef is loading all records as objects into memory for group by
It's Eager Loading which we do not support. It should be processed by EF Core if you remove complexity. Place details closer to projection and remove grouping - it is not needed here.
var qry =
from emp in db.EmployeeInfo
from branch in db.BranchInfo
where emp.EmpCode == "1002" && emp.Status == 0 && emp.BranchCode == branch.BranchCode
select new EmployeeOutput
{
EmpAvatar = emp.EmpAvatar,
EmpCode = emp.EmpCode,
EmpId = emp.EmpId,
EmpName = emp.EmpName,
EmpPhone = emp.EmpPhone,
EmpPic = (from attach in db.Attachment
where attach.Type == 1 && attach.Status == 0 && attach.ItemId == emp.EmpId
select attach.Url).ToList(),
BranchAddress = branch.BranchAddress,
BranchName = branch.BranchName
};
var temp = qry.FirstOrDefault();
ok. It's like the best way to do it now.
LinqToDBForEFTools.Initialize();
It's global ?
Initialization of the first run of my project
Yes it is global, but it is idempotent, so you can call as many times as you need.
It is required only if you use linq2db extensions Delete
, Update
, Insert
etc. and do not call ToLinqToDB()
method before.
LinqToDBForEFTools.Initialize()
also called automatically from LinqToDBForEFTools
static constructor.
So usually it is already initialized.
Closing for now. Will reopen if needed.
my code
translate sql
error .
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。