Tag: linq

entity framework,代码优先和全文search

我意识到很多问题都被问及全文search和entity framework,但我希望这个问题有点不同。 我使用的是entity framework,Code First,需要进行全文search。 当我需要执行全文search时,我通常也会有其他标准/限制 – 比如跳过前500行,或者在另一列上过滤等等。 我看到这已经使用表值函数处理 – 请参阅http://sqlblogcasts.com/blogs/simons/archive/2008/12/18/LINQ-to-SQL—Enabling-Fulltext-searching.aspx 。 这似乎是正确的想法。 不幸的是,直到entity framework5.0(即使那样,我相信它们不被Code First支持),表值函数也不被支持。 我真正的问题是什么build议最好的方式来处理这个,entity framework4.3和entity framework5.0。 但具体来说: 除了dynamicSQL(例如通过System.Data.Entity.DbSet.SqlQuery ),是否有任何选项可用于Entity Framework 4.3? 如果我升级到entity framework5.0,有没有办法,我可以使用表值函数与代码第一? 谢谢,埃里克

为什么.ForEach()在IList <T>而不是IEnumerable <T>?

可能重复: 为什么IEnumerable接口上没有ForEach扩展方法? 我注意到在编写LINQ-y代码时,.ForEach()是一个很好用的习惯用法。 例如,下面是一段代码,它接受以下input,并生成这些输出: { "One" } => "One" { "One", "Two" } => "One, Two" { "One", "Two", "Three", "Four" } => "One, Two, Three and Four"; 和代码: private string InsertCommasAttempt(IEnumerable<string> words) { List<string> wordList = words.ToList(); StringBuilder sb = new StringBuilder(); var wordsAndSeparators = wordList.Select((string word, int pos) => { if (pos == […]

将使用LINQ to SQL帮助防止SQL注入

我正在build立一个公共站点,我首先想到的是SQL注入。 我有一些我正在保存的文本字段,正在使用LINQ来更新/写入数据库。 我安全使用LINQ? 这个例子是创build用户帐户。 Data.MemberRegistrationDataContext context = new MemberRegistrationDataContext(); Data.tbl_Member_UserProfile profile = new tbl_Member_UserProfile(); profile.SSN = Convert.ToDecimal(Session["tempMemberSSN_Registration"]); profile.UserName = userName; profile.Password = password; profile.EmailAddress = email; profile.QuestionID = qID; profile.QuestionResponse = securityAnswer; profile.LastModDt = DateTime.Now; profile.LastModBy = "web"; context.tbl_Member_UserProfiles.InsertOnSubmit(profile); context.SubmitChanges(); 这个例子是改变密码 MemberRegistrationDataContext dc = new MemberRegistrationDataContext(); var mProfileRecord = dc.tbl_Member_UserProfiles.Single(c => c.SSN == sSSN); mProfileRecord.Password […]

linq:按顺序sorting

我怎样才能改变下面的代码,每次从数据库中获得50个不同的随机数据? return (from examQ in idb.Exam_Question_Int_Tbl where examQ.Exam_Tbl_ID==exam_id select examQ).OrderBy(x=>x.Exam_Tbl_ID).Take(50);

将DataRowCollection转换为IEnumerable <T>

我想在.NET 3.5中做这样的事情。 什么是最快的方法? IEnumerable<DataRow> collection = TypedDataSet.TypedTableBase<DataRow>.Rows as IEnumerable<DataRow>;

如何从列表中删除空string,然后从列表中删除重复的值

比方说,我有一个来自表的列值的列表,我如何删除空string和重复的值。 请看下面的代码: List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList(); 这就是我刚刚编写的代码,但是Amiram的代码更加优雅,所以我会select这个答案是我做的: DataTable dtReportsList = someclass.GetReportsList(); if (dtReportsList.Rows.Count > 0) { List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList(); dtList.RemoveAll(x=>x == ""); dtList = dtList.Distinct().ToList(); rcboModule.DataSource = dtList; rcboModule.DataBind(); rcboModule.Items.Insert(0, new RadComboBoxItem("All", "All")); }

你可以在IronPython中使用LINQtypes和扩展方法吗?

是否有可能在IronPython中使用LINQtypes和扩展方法? 如果这样怎么样? 同样的事情也经常有更多的pythonic?

LINQ to Entities如何更新logging

好的,所以我对EF和LINQ都很陌生。 我已经想出了如何插入和删除,但由于某种原因更新似乎逃脱我的把握。 这是我的代码示例: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", Gender = "Male }; dataBase.Customers.AddObject(c); dataBase.SaveChanges(); 上面创build并添加一个logging就好了。 Customer c = (from x in dataBase.Customers where x.Name == "Test" selext x).First(); dataBase.Customers.DeleteObject(c); dataBase.SaveChanges(); 以上有效删除指定的logging。 现在我该如何更新? 我似乎无法find实体集合上的“ UpdateObject() ”方法。

C#List <> GroupBy 2的值

我在Framework 3.5上使用C#。 我期待通过两个属性快速分组通用列表<>。 为了这个例子,我们可以说我有一个订单types的列表,具有CustomerId,ProductId和ProductCount属性。 我怎样才能得到由CustomerId和ProductId使用lambdaexpression式分组的ProductCounts的总和?

如何在entity framework中进行“in”查询?

我如何做一个select在LINQ实体从列表中select行键? 像这样的东西: var orderKeys = new int[] { 1, 12, 306, 284, 50047}; var orders = (from order in context.Orders where (order.Key in orderKeys) select order).ToList(); Assert.AreEqual(orderKeys.Count, orders.Count); 我尝试使用一些答案中提到的Contains方法,但它不起作用,并引发此exception: LINQ to Entities不识别方法'布尔包含[Int32](System.Collections.Generic.IEnumerable`1 [System.Int32],Int32)'方法,并且此方法不能转换为存储expression式。