假设我有一个int列表,其中包含一个I列表。我有一个linq表,我想返回一个特定的列,但仅当linq表的ID等于int列表中的任何ID时才返回。
到目前为止,我有:
dc.tb_References.SelectMany(n => n.ID == ids).ToList();
在sql中,我只需要这样写:
SELECT Column_Name from Table where ID in (1,2,3,4)
我一直在谷歌上搜索,但我找不到我要找的东西。有谁有什么建议吗?我想继续使用lambda表达式。
我是LINQ的新手,所以如果这是一个愚蠢的问题,请原谅我,但是将LINQ结果集转换为特定类列表的最佳方法是什么?
例如,假设我定义了一个名为clsTest的类。它有三个属性,Prop1、Prop2和Prop3 (都是字符串)。我需要做的是从一个linq结果集生成一个( clsTest)列表,在其中我选择包含在类中的相同字段。
例如,如果我得到这样的结果:
Dim i as new MyDataContext
Dim results = From o in i.SomeTable
Select o.Field1, o.Field2, o.Field3
我如何获得结果成
我有一个列表(自定义类) 我想通过linq从其中提取所有'name‘字符串的列表 我知道如何处理循环,但我需要使用线性的、简短的linq指令。 我已经检查过这个help C# Extract list of fields from list of class 但是我在linq的正确语法上有问题。 特别是因为我想提取一个新的列表(字符串) Class Student
Sub New(ByVal NewName As String, ByVal NewAge As Integer)
Name = NewName
Age = NewAge
E
是否可以比较Linq查询中的两个EntityCollection?
我试过这样做:
from t in _bdd.Table
where (idList).All(id=> t.ids.Contains(id))
select i).FirstOrDefault()
其中idList和ids均为EntityCollection
但我得到了一个NotSupportedException:
"Unable to create a constant value of type (ID) Only primitive types (
我正在使用LINQ to SharePoint查询从SharePoint列表返回项目。
var myOpenTasksQuery = from myTasks in tasks
where myTasks.TaskStatus != TaskStatus.Completed
select myTasks
然而,我正在查询的列表,一个OOTB任务列表,有许多多项选择字段(状态,优先级),它们被转换为枚举。在我的查询结果中,任务项的状态返回为"_2Normal",而不是我期望的"(2
我有一个获取id列表的函数,我需要返回一个列表,该列表与与id相关联的描述相匹配。例如:
public class CodeData
{
string CodeId {get; set;}
string Description {get; set;}
}
public List<CodeData> GetCodeDescriptionList(List<string> codeIDs)
//Given the list of institution codes, return a list of CodeData
//having th
我有一个数据结构,其中变量是object类型的。但是,我知道在运行时,这个对象肯定是一个List<T>,其中T应该涵盖多个情况(例如,int、string、.)。在下面的代码中,我想使用List<T>-specific功能,例如Linq函数。
通过下面的检查,我确定,这是一个列表:
if (constantExpression.Value.GetType().GetGenericTypeDefinition() == typeof(List<>))
{
// Want to use Linq here
}
这个是可能的吗?不幸的是,我在网上没有发现
我很难想出一种方法来列出非唯一的SelectListItems,然后得到一个唯一的Selectlistitems列表。我正在尝试使用linq来做这件事...我尝试的代码是这样的
var queryResults =
from p in PatientList
group p by p.Value into g
select new SelectListItem { Text= g.Key, Value= g.Max(p => p.Value.Split('|')[1]) };
使用这种方法,我得到的列表与我之前使用的列表完全相同。现在,当涉
我使用以下Linq查询:
from p in People
where p.Name == "George Lucas"
select p.TitlesActedIn
其中TitlesActedIn是一个列表。人民与TitlesActedIn
但我错了:
'System.Data.Services.Client.ResourceExpression'.:无法将“System.Linq.Expressions.PropertyExpression”类型的对象强制转换为InvalidCastException
请提出解决办法。
假设你有一个对象列表:
private List<Person> lstPersons = new List<Person>();
在其中,人被定义为:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Mail { get; set; }
}
您能否使用Linq从上述列表返回多维数组,其中第一个维度是记录索引,第二个维度是名称,第三个维度是电子邮件?
我有一个包含模型的列表,其中每个模型都有一个编号。
现在我想搜索包含其他模型的另一个列表,其中每个模型都可能具有第一个列表中的数字。
这是我的模型的样子:
public class Task
{
int AddressId; //foreign key
}
public class Address
{
int Id; //primary key
}
现在我有了一个地址列表和一个任务列表。我想将我的任务列表过滤到那些AddressId在我的地址列表中的任务。
我的linq会是什么样子的?
result = tasks.Where(t => t.AddressId == ??