I have an employee table with a bigint primary key bigint in the database and an entity data model with the first database approach. The employee class has this structure.
public partial class Employee { public long Emp_No { get; set; } public string Name { get; set; } public string Family { get; set; } ... }
I am writing this basic query with Entity Framework
List<long> ids = new List<long>() {1,2,3,4,5,6} database.Employees.Where(q => ids.Contain(q.Emp_No)).ToList();
Create a query as follows:
SELECT [Extent1].[Emp_No] AS [Emp_No], [Extent1].[Name] AS [Name], [Extent1].[Family] AS [Family], ... FROM [dbo].[Employee] AS [Extent1] WHERE [Extent1].[Emp_No] IN (cast(0 as bigint), cast(1 as bigint), cast(2 as bigint), cast(3 as bigint), cast(4 as bigint), cast(5 as bigint), cast(6 as bigint))
As you can see, there is no unnecessary cast to bigint in the query, while both types of the Emp_No and ids array are equal to long , it causes bad Emp_No , especially when the ids array has many elements.
How to remove this redundant listing?
c # sql-server expression entity-framework
Vahid jafari
source share