linq-to-entities

LINQ throwing invalid cast exception on a bigint

本小妞迷上赌 提交于 2019-12-23 07:17:32
问题 I have a LINQ query that looks something like this: var clintLst = (from clntDt in ent.ClientDatas where clntDt.CompanyName.Substring(0,searchWord.Length).Equals(searchWord, StringComparison.CurrentCultureIgnoreCase) orderby clntDt.CompanyName select new { ClientDataID = clntDt.ClientDataID, CompanyName = clntDt.CompanyName, ContactName = (clntDt.ContactFirstName + " " + clntDt.ContactLastName), CompanyLocation = clntDt.Location.LocationCity.CityName + ", " + clntDt.Location.LocationState

LINQ throwing invalid cast exception on a bigint

北慕城南 提交于 2019-12-23 07:17:25
问题 I have a LINQ query that looks something like this: var clintLst = (from clntDt in ent.ClientDatas where clntDt.CompanyName.Substring(0,searchWord.Length).Equals(searchWord, StringComparison.CurrentCultureIgnoreCase) orderby clntDt.CompanyName select new { ClientDataID = clntDt.ClientDataID, CompanyName = clntDt.CompanyName, ContactName = (clntDt.ContactFirstName + " " + clntDt.ContactLastName), CompanyLocation = clntDt.Location.LocationCity.CityName + ", " + clntDt.Location.LocationState

Can't Translate Extension Method Into Store Expression

喜你入骨 提交于 2019-12-23 05:13:36
问题 I have an extension method as follows: public static bool SatisfiesSomeCondition(this Post post, SomeObj someObj) { return post.SomeObjId == someObj.SomeObjId; } And i'm trying to use it like this: var query = ctx.Posts.Where(p => p.SatisfiesSomeCondition(someObj)).ToList(); But i get the error: LINQ to Entities does not recognize the method 'Boolean SatisfiesSomeCondition(xx.xx.xx.Post, xx.xx.xx.SomeObj)' method, and this method cannot be translated into a store expression. If i change the

How can I search into database with WPF and Linq-to-entities model

安稳与你 提交于 2019-12-23 05:00:27
问题 I prepare a WPF project, where I want to implement a more complex search. I use LINQ to entities through the ADO.NET Entity model and plan to do the display in WPFToolkit DataGrid. My search window should allow search by a few different criteria. My idea is to be able to write in (for example) name, surname and occupation textboxes in the application and receive a list of all people in the selected table that correspond to all 3 search parameters. I want to be able to search when all are

Some part of your SQL statement is nested too deeply

本秂侑毒 提交于 2019-12-23 04:43:56
问题 I have the following code [WebGet] public Bid GetHighestBidInOpenAuctions(int auctionEventId) { var auctionEvent = CurrentDataSource.AuctionEvents.Where(x => x.Id == auctionEventId).FirstOrDefault(); var auctionIds = CurrentDataSource.Auctions.Where(x => x.AuctionEventId == auctionEventId && x.Ends > DateTime.UtcNow).Select(x => x.Id).ToList(); var bids = CurrentDataSource.Bids.Where(x => auctionIds.Any(t => t == x.AuctionId)); // If the auction Event has not yet started or there are no bids

EF Linq query with conditional include

我的梦境 提交于 2019-12-23 03:29:35
问题 So I have the following Linq query: var member = (from mem in context.Members.Include(m => m.MemberProjects.Select(mp => mp.Project)) where mem.MemberId == memberId select mem).FirstOrDefault(); This returns a Member entity, with a set of MemberProjects that have a Project child. I would like to limit the MemberProjects to only those for which the Project child has a property ProjectIdParent == null . One of my failed attempts might make the intent clearer: var member = (from mem in context

How can I join data with Linq to Entities and WCF Data Services?

人走茶凉 提交于 2019-12-23 03:24:31
问题 I have 4 entities that are related as follows: LocalAgency<-0..1----1->Agency<-0..1----1->Organization<-0..1----1->Customer In other words, a LocalAgency has one related Agency , etc. The data model is set up using Entity Framework (containing navigation properties to peruse those relationships), and a WCF DataService is set up to provide that data to clients. On the client side that consumes the DataService , I'm trying to return a query of local agencies based on a customer name, but haven

Dynamically grouping by Day/Week/Month/Year at Runtime

天涯浪子 提交于 2019-12-23 02:28:25
问题 I'd like to group my query differently based on an int passed into my function. Currently I have this very hacky solution: `.GroupBy(occurrence => new { date = // Bucket by day. timeBucket == 0 ? DbFunctions.TruncateTime(occurrence.occurrenceDate) : // Bucket by week. timeBucket == 1 ? DbFunctions.AddDays(DbFunctions.CreateDateTime(occurrence.occurrenceDate.Year, 1, 1, 0, 0, 0), 7*(occurrence.occurrenceDate.DayOfYear/7)) : // Bucket by month. timeBucket == 2 ? DbFunctions.TruncateTime

EF Intersect Syntax

久未见 提交于 2019-12-23 01:41:49
问题 A UI allows users to select one or many tags. I would like to select all Nodes that have ALL that tags the user entered associated, not just a single tag. public JsonResult SearchNodesByTags(string[] tags) { var dbTags = _DbContext.Tags.Where(t => tags.Contains(t.DisplayName)).ToList(); var nodes = _DbContext.Nodes.Where(n => n.Tags.Intersect(dbTags).Any()); // Error about intersection with non primitive return Json(nodes); } 回答1: You can do this in one statement: var nodes = _DbContext.Nodes

Update database with LINQ to Entities

主宰稳场 提交于 2019-12-23 01:29:09
问题 I've been doing some research on how to update an existing record using LINQ, but I'm not having any luck. This is the method I've created - intellisense does not like the db.SubmitChanges() . public void updateRestaurant(int RestID, int HoursID, string Web, string Desc) { RestaurantsEntities db = new RestaurantsEntities(); RESTAURANT restDetails = (from RESTAURANT in db.RESTAURANTs where RESTAURANT.REST_ID == RestID select RESTAURANT).Single(); restDetails.HOURS_ID = HoursID; restDetails