整数包含使用LINQ [英] Integer Contains Using Linq
问题描述
我有一些困难,写一个LINQ查询,将检查一个整数,连续的数字是否包含在表的主键。因此,假设有一个名为员工
与列主键 Employees.Id
表。假设这个主键在SQL Server数据类型 INT
的。我想编写使用实体框架代码首先将返回其主键包含字符串456.喜欢的东西全体员工LINQ查询:
字符串过滤器=456;
变种结果从E在myDbContext.Employees
,其中e.Id.Contains(过滤器)
选择e =;
的问题是,包含方法未在C#供整数数据类型... 对>
尝试:
VAR结果从= E在myDbContext.Employees
,其中SqlFunctions.StringConvert((双)e.Id)。载有(过滤器)
选择e;
I'm having some difficulty writing a linq query that will check whether the consecutive digits in an integer are contained in the primary key of a table. So, suppose there is a table called Employees
with a primary key on the column Employees.Id
. Suppose this primary key is of Sql Server datatype INT
. I would like to write a linq query using Entity Framework Code First that will return all employees whose primary key contains the string 456. Something like:
string filter = "456";
var results = from e in myDbContext.Employees
where e.Id.Contains(filter)
select e;
The problem is that the Contains method is not offered for integer datatypes in C#...
Try:
var results = from e in myDbContext.Employees
where SqlFunctions.StringConvert((double)e.Id).Contains(filter)
select e;
这篇关于整数包含使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!