听说
List<int> lstBizIds = new List<int>() { 1, 2, 3, 4, 5 };
List<int> lstProjectIds = context.Projects.Where(x =>lstBizIds.Contains(x.businessId)).Select(x => x.projectId).ToList();
会翻译成sql 是 in
SELECT Id FROM ProjectsWHERE UserId IN (1, 2, 3, 4, 5, 6)
而
List<int> lstBizIds = new List<int>() { 1, 2, 3, 4, 5 };
List<int> lstProjectIds = context.Projects.Join(lstBizIds, p => p.businessId, u => u, (p, u) => p.projectId).ToList();
会翻译成sql 是
SELECT Id
FROM Projects
INNER JOIN (VALUES (1), (2), (3), (4), (5)) AS Data(Item) ON Projects.UserId = Data.Item
但是我用join的时候,sql server 监听数据库的sql语句时,join反而是
SELECT Id FROM Projects 的
而且在使用ToListAsync等异步方法的时候,Join性能很差,用Contains反而会很好。这是为什么呢
相关问题
- SQL join to get the cartesian product of 2 columns
- Query self-join with Sequelize, including related
- Multiple (left, cross?) JOINs in MS Access
- Adding Inner join and where clause to INSERT INTO
- SQL Joined Tables - Multiple rows on joined table
相关文章
- EF 插入值问题
- SQL Server 2008: Joining results of STORED PROCEDU
- Join two tables in MySQL, returning just one row f
- Oracle USING clause best practice
- Redshift table update with join
- In C#, best way to check if stringbuilder contains
- C# Check if string contains any matches in a strin
- Join datatables using column names stored in varia
就和sql里的 join和 like '%hello%'的区别
Join:连接,返回的T where T is class;Contains:(是否)包含,返回 bool;
上面的查询场景完全不需要用 Join