linq-to-entities

Select a range with Entity Framework

独自空忆成欢 提交于 2019-12-18 13:23:17
问题 I have an issue trying to maximize the performance of our listview that has pages. I want the entity framework to do a select statement, but only return a range of the result (range = the items of one page of the listview). I have searched google but didn't find any results on this. I only found that I can do a .ToList().GetRange(start index, end index), but then all items would be loaded in memory, and that is what I would like to avoid... Can someone tell me if this can be done? (I don't

Updating Entity Framework Model

被刻印的时光 ゝ 提交于 2019-12-18 12:47:41
问题 I have just started using EF and found it cool, but I ran into a problem, Problem: I changed my DB schema of a column inside the table User, It was Varbinary(50) previously I then changed it into VarChar(50), and then inside the MyModel.edmx designer I chose "Update model from database", after clicking finish I received this error. Error: Error 2019: Member Mapping specified is not valid. The type 'Edm.Binary [Nullable=False,DefaultValue=,MaxLength=100,FixedLength=False]' of member 'Email' in

Linq If Statement

只谈情不闲聊 提交于 2019-12-18 10:57:12
问题 How would i write something like this in linq to entities sb.Append(" WHERE question.question_isdeleted = 0"); if (catid != 0) sb.AppendFormat(" AND (CatID IN ({0}))", catsSTR); if(!string.IsNullOrEmpty(AuthorID)) sb.Append(" AND (question_ownerid = @id)"); i think I just need the syntax to write an if conditional in linq to entities 回答1: I would use dot notation here: var query = questions.Where(q => !q.IsDeleted); if (catId != 0) { query = query.Where(q => cats.Contains(q.CatID)); } if

LINQ to Entities not returning expected result

风格不统一 提交于 2019-12-18 09:13:17
问题 I am using a view to return a complex search query. When I usin linq to query against EF it is returning the same row 3 times(the actual rowcount is correct). using LinqPad I have run the same linq against my ef entity and the actual database view. ReadmitPatientList .AsQueryable() .Where("PatientLastName.StartsWith(\"cooper\")") .OrderBy (rpl => rpl.PatientLastName) .Dump(); That is the linq I am using for both. linqpad shows the lambda as this: EF: ReadmitPatientList.MergeAs (AppendOnly)

LINQ to Entities StringConvert(double)' cannot be translated to convert int to string

倖福魔咒の 提交于 2019-12-18 08:56:06
问题 Problem Need to convert int to string using EF4 + SQL CE4. The recommended option of using SqlFunctions.StringConvert(double) still gives me errors. Option 1 (original). This gives me error: public static IEnumerable<SelectListItem> xxGetCustomerList() { using (DatabaseEntities db = new DatabaseEntities()) { var list = from l in db.Customers orderby l.CompanyName select new SelectListItem { Value = l.CustomerID.ToString(), Text = l.CompanyName }; return list.ToList(); } } Option 2 (most

Entity Framework, MVC 3, OrderBy in LINQ To Entities

久未见 提交于 2019-12-18 08:53:24
问题 I've got the following query: model.Page = db.Pages .Where(p => p.PageId == Id) .Include(p => p.Series .Select(c => c.Comics .Select(col => col.Collection))) .SingleOrDefault(); This works great, although I now need to order the Comics by a property called 'ReadingOrder'. I've tried: model.Page = db.Pages .Where(p => p.PageId == Id) .Include(p => p.Series.Select(c => c.Comics.OrderBy(o => o.ReadingOrder) .Select(col => col.Collection))) .SingleOrDefault(); But this results in the following

LINQ to SQL Select Distinct by Multiple Columns and return entire entity

五迷三道 提交于 2019-12-18 08:27:28
问题 I am working with a third party database and need to select a distinct set of data for the specific market that I am looking into. The data is the same for each market, so it is redundant to pull it all in, and I don't want to hardcode any logic around it as we are working with the vendor to fix the issue, but we need a fix that will work with the vendors fix as well as the way the database is currently as it could be some time before thier fix goes live. I do not want to group by anything as

The entity or complex type … cannot be constructed in a LINQ to Entities query

蓝咒 提交于 2019-12-18 08:22:32
问题 Why does one method work but not the other, when it seems they are both doing the same thing, i.e. constructing an entity. My question then, is there a way to construct the entity in a L2E query instead of having to use just Linq or indeed both? This works fine... var queryToList = (from ac in ctx.AuthorisationChecks where wedNumbers.Contains(ac.WedNo) orderby ac.WedNo, ac.ExpAuthDate, ac.ActAuthDate select new AuthorisationCheck { Blah = ac.Blah }).ToList(); model.AuthorisationChecks =

Linq to Entity comparing strings ignores white spaces

 ̄綄美尐妖づ 提交于 2019-12-18 07:46:29
问题 When using LINQ to entity doing string comparisons will ignore white spaces. In my table, I have an nchar(10) column so any data saved if it is not 10 characters will fill the rest with empty spaces. Below i am comparing the "ncharTextColumn" with the "Four" string. And even though the ncharText will equal "Four " It results in a match and the "result" variable will contain 1 record TestEntities1 entity = new TestEntities1(); var result = entity.Table_1.Where(e => e.ncharText == "Four"); Is

How to get a byte array length using LINQ to Entities?

血红的双手。 提交于 2019-12-18 07:39:50
问题 I have a Document class that stores the data of that document as a byte array. I need to check the size of the array, using LINQ to Entities. I have tried the following: [long Linq query here...] o.Data.Length < 800000) The problem is I get the following exception: The LINQ expression node type 'ArrayLength' is not supported in LINQ to Entities." Is there any other way to check the size of the byte array? 回答1: Use SqlFunctions.DataLength Method (Byte[]) to compare length. yourquery.....