Tag: linq

找不到使用System.Data.Linq

我在asp.net 4和VS 2010中使用C#,EF 4。 我正在尝试using System.Data.Linq使用此代码加载命名空间System.Data.Linq ,我收到此错误: 错误2命名空间“System.Data”中不存在类型或命名空间名称“Linq”(您是否缺少程序集引用?) 知道我做错了什么。

如何在c#/ Linq中获取确定列名的值?

我想知道是否有可能获得明确的列名称的值? 例如, SELECT NAME FROM PERSON; string NAME; a… == NAME); 问题是列名称可能会更改,它并不总是“NAME”列。 因此,我需要一个解决方案,我可以动态地将列名称传递给查询。

按LINQ C#出现单词对列表进行排序

我已将数据存储在列表中 List list = new List(); SearchResult sr = new SearchResult(); sr.Description = “sample description”; list.Add(sr); 假设我的数据存储在描述字段中 “JCB Excavator – ECU P/N: 728/35700” “Geo Prism 1995 – ABS #16213899” “Geo Prism 1995 – ABS #16213899” “Geo Prism 1995 – ABS #16213899” “Wie man BBA reman erreicht” “this test JCB” “Ersatz Airbags, Gurtstrammer und Auto Körper […]

Serialize.Linq在WCF代理层中不起作用

我使用Serialize.Linq发送并在WCF应用程序服务中的客户端和服务器之间接收Expression<Func>查询,因为Expression<Func>无法序列化 一切似乎都很好但是 当我添加引用此库到wcf代理层并添加服务器引用我的Web服务 构建我的项目时会遇到这样的错误 ExpressionNodeOfNewExpressionQsd8_SODT’ does not implement inherited abstract member ‘Serialize.Linq.Nodes.ExpressionNode.ToExpression(Serialize.Linq.ExpressionContext)’ ExpressionNodeOfTypeBinaryExpressionQsd8_SODT’ does not implement inherited abstract member ‘Serialize.Linq.Nodes.ExpressionNode.ToExpression(Serialize.Linq.ExpressionContext)’ etc … 似乎WCF为这个库创建自动生成的代理类而不是使用主类,而我将参考Serialize.Linq程序集添加到代理项目但没有帮助解决我的问题 您可以非常简单地测试并显示此问题 像这样 创建Wcf服务应用程序并将参考Serialize.Linq添加到项目 public interface IService1 { [OperationContract(Name = “GetByPredicate”)] List Get(ExpressionNode expression); [OperationContract] List Get(); } public class Person { public int ID { get; set; } public string Name { […]

使用LINQ从选择中排除列

我正在使用Entity Framework Code First开发WCF RESTful Web服务。 我有一个表有很多列的Users 。 我这样做是为了得到一个特定的用户: context.Configuration.ProxyCreationEnabled = false; var users = from u in context.Users where u.UserId == userId select u; 在此表上,有一个密码列,我不想返回此列。 如何从该选择中排除密码列?

LINQ to Entities无法识别方法’Int32 Parse(System.String)’方法,

我正在使用Entity Framework,我有一行代码将字符串字段(id)转换为int并与数字进行比较 students = students.Where(s => (Int32.Parse( s.id)>5555)); 每当我尝试运行它时,我都会收到此错误。 “LINQ to Entities无法识别方法’Int32 Parse(System.String)’方法,并且此方法无法转换为商店表达式。” 我尝试了不同的东西,没有任何工作,所以任何帮助都会很棒。

将List 拆分为连续数组

我有一个排序的List如{ 1, 2, 3, 4, 6, 7, 9 } 我想把它分成几个组 – 每个组都有这样的连续数字: { {1, 2, 3, 4}, {6, 7}, {9} } 我知道我可以使用for循环来遍历列表,并在当前值和先前值之间进行比较,然后决定是追加到最后一个组还是创建一个新组。 但我想找到一种“漂亮”的方式来做到这一点。 也许使用LINQ? 编辑: 我从项目more-itertools中找到了一个python代码: def consecutive_groups(iterable, ordering=lambda x: x): for k, g in groupby( enumerate(iterable), key=lambda x: x[0] – ordering(x[1]) ): yield map(itemgetter(1), g)

如何在entity framework查询中将DateTime转换为TimeSpan

我有Entity Framework 6的LINQ查询: var timeCapturesQuery = Context.TimeCaptures .Where(t => && t.StartDateTime.TimeOfDay startTime); EndTime和StartTime是TimeSpan类型的参数,StartDateTime和EndDateTime是datetime表上的列。 不幸的是,我在运行时收到此错误: LINQ to Entities不支持指定的类型成员’TimeOfDay’。 仅支持初始化程序,实体成员和实体导航属性。 如何在此LINQ查询中从DateTime(即SQL中的datetime的time )获取TimeSpan ?

如何在groupby和sum行和列中关系表和Where(asp-route-id)

第一张表是发电厂名称列表 public class PowerPlants { public int ID { get; set; } [Required] public string PowerPlantName { get; set; } [Required] public string PowerPlantShortName { get; set; } [Required] public string PowerPlantCode { get; set; } public virtual ICollection REHPData { get; set; } public virtual ICollection BudgetYearlyAllocation { get; set; } } 第二个表是BudgetYear表 public […]

如何使用Linq XML强制显式标记关闭?

这与以下问题相同: 使用System.Xml.Linq命名空间的显式元素关闭标记 但我使用Net 4.0,答案不再适用。 问题是我保存标签没有真正的值,我的输出XML看起来像这样: 但我需要的是始终打开和关闭标签,即 问题 :怎么做? 编辑 1 添加空节点: if (field_xml == null) // always true, because I create the file for the first time { field_xml = new XElement(XMLKeys.field,String.Empty); table_xml.Add(field_xml); } field_xml.SetAttributeValue(XMLKeys.name, field_info.Name); // … setting some other attributes of this node 然后,保存xml: var writer = new FullEndingXmlTextWriter(parameters.OutputFilename, Encoding.UTF8); root_xml.Save(writer); FullEndingXmlTextWriter是Evil Greebo指出的专门类(它应该强制显式关闭标记)。