案例1:
我在两个上下文中通过ToList()方法加入了两个不同的DB Context.
案例2:
并尝试加入第一个Db Context ToList()和第二个AsQueryable().
两者都适合我.我想知道的是那些关于性能和功能的加入之间的区别.哪一个更好 ?
var users = (from usr in dbContext.User.AsNoTracking()
select new
{
usr.UserId,
usr.UserName
}).ToList();
var logInfo= (from log in dbContext1.LogInfo.AsNoTracking()
select new
{
log.UserId,
log.LogInformation
}).AsQueryable();
var finalQuery= (from usr in users
join log in logInfo on usr.UserId equals log.UserId
select new
{
usr.UserName,
log.LogInformation
}.ToList();
Run Code Online (Sandbox Code Playgroud) 这是我用过的LINQ查询
var result = (from price in inventoryDb.Pricing.AsNoTracking()
where price.Quantity > 0m
select new
{
TagNo = price.TagNo,
SellingRate = price.SellingRate,
Quantity = price.Quantity
}).ToList();
Run Code Online (Sandbox Code Playgroud)
基于Quantity我需要在列表中生成重复项的值.
输出:
result = [0]{TagNo="100", SellingRate=1500.00, Quantity=1}
[1]{TagNo="101", SellingRate=1600.00, Quantity=2}
Run Code Online (Sandbox Code Playgroud)
预期结果:
result = [0]{TagNo="100", SellingRate=1500.00}
[1]{TagNo="101", SellingRate=1600.00}
[2]{TagNo="101", SellingRate=1600.00}
Run Code Online (Sandbox Code Playgroud)