Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用实体框架&;将Id列存储到变量中;C#_C#_Sql Server_Entity Framework - Fatal编程技术网

使用实体框架&;将Id列存储到变量中;C#

使用实体框架&;将Id列存储到变量中;C#,c#,sql-server,entity-framework,C#,Sql Server,Entity Framework,我想将表中的所有id列存储到一个允许我将其与文本框中的数字进行比较的东西中。在这里,试试这个 var myvariable = myDataContext.MyTable.Select(x=>x.Id).ToArray(); 来,试试这个 var myvariable = myDataContext.MyTable.Select(x=>x.Id).ToArray(); 如果存储Id值以进行比较,例如HashSet将更有效地收集所有Id并将其与其他值进行比较 var allIds

我想将表中的所有id列存储到一个允许我将其与文本框中的数字进行比较的东西中。

在这里,试试这个

var myvariable = myDataContext.MyTable.Select(x=>x.Id).ToArray();
来,试试这个

var myvariable = myDataContext.MyTable.Select(x=>x.Id).ToArray();

如果存储
Id
值以进行比较,例如
HashSet
将更有效地收集所有
Id
并将其与其他值进行比较

var allIds = dataContext.YourTableable.Select(row => row.Id);

HashSet<int> idsOfYourTable = new HashSet<int>(allIds);

if(idsOfYourTable.Contains(34) == true)
{
    // do your staff
}
var allIds=dataContext.yourtabled.Select(row=>row.Id);
HashSet idsOfYourTable=新的HashSet(allIds);
if(idsOfYourTable.Contains(34)=true)
{
//你的员工呢
}

如果存储
Id
值进行比较,例如
HashSet
将更有效地收集所有
Id
并将其与其他值进行比较

var allIds = dataContext.YourTableable.Select(row => row.Id);

HashSet<int> idsOfYourTable = new HashSet<int>(allIds);

if(idsOfYourTable.Contains(34) == true)
{
    // do your staff
}
var allIds=dataContext.yourtabled.Select(row=>row.Id);
HashSet idsOfYourTable=新的HashSet(allIds);
if(idsOfYourTable.Contains(34)=true)
{
//你的员工呢
}