linq-to-entities

Which method of canonical EntityFunctions for .ToString()

╄→尐↘猪︶ㄣ 提交于 2019-12-13 07:58:39
问题 I am using EF and if I use expression like: JobLinkId = jobItem.joblinkid.ToString() it throws error because it is C# function. Which method of EF canonical functions should I use for this? 回答1: I'm guessing that you're trying to use ToString in Linq to Entities query. If so then its impossible to use it there. The only walkaround i know is to use ToList on query and then use Linq to Objects to get result with ToString . 回答2: To something like this: instead of JobItem.joblinkid.ToString() use

How to joint two set of retrieved data using LinQ To Entities

霸气de小男生 提交于 2019-12-13 07:44:48
问题 I am using dbcontext Code first to get a query base on this condition for the Classes (tables) below: Creator != null && ArticleAttached != null && !IsCancelled Problem : How to get data from the classes (tables) and show Article Title, No. of Likes, No. Of Comments, Total Assigned, TotalResponded A) I use dbcontext as follows: var ListArticles = dbcontext.LearningActivites .Where(la => la.Creator != null && la.ArticleAttached != null && !la.IsCancelled) .Select(la => new { Id = la.Id, Title

split field a string in a linq

大兔子大兔子 提交于 2019-12-13 07:09:11
问题 I tried in different ways to accomplish this but I can make it work I have a class called CampoConfiguracionVista Defined like this public class CampoConfiguracionVista { public CampoConfiguracionVista() { } public int IDCampo { get; set; } public int IDConfiguracion { get; set; } public string Nombre { get; set; } public bool ValidationEspecial { get; set; } public bool Requerido { get; set; } public int IDTipodato { get; set; } public int? minimo { get; set; } public int? maximo { get; set;

Where Clause With Null Object Using Entity Framework v5.0RC

£可爱£侵袭症+ 提交于 2019-12-13 07:01:51
问题 I was trying to do the following public IList<Category> GetMainCategories() { return _context.Category .Where(x => x.ParentCategory == null) .OrderBy(x => x.SortOrder) .ToList(); } However, no matter what I try this returns no results even though I can see in the collection that ALL ParentCategory's are null? I have read EF has problems with nulls like this and have also tried .Where(x => x.ParentCategory.Equals(null)) And .Where(x => Equals(x.ParentCategory.Id, null)) .Where(x => Equals(x

How to solve issue “Could not translate expression …into SQL and could not treat it as a local expression.” [duplicate]

走远了吗. 提交于 2019-12-13 06:26:59
问题 This question already has answers here : Linq “Could not translate expression… into SQL and could not treat it as a local expression.” (3 answers) Closed 5 years ago . I have code below: void Main() { var q = from a in Applicants where(a.Claims.Any()) select a.Claims.Sum(c => c.TotalClaimAmount()); q.Dump(); } public static class MyExt { public static decimal TotalClaimAmount(this Claim c) { var t = c.Accommodations.Sum(a => a.AmountClaimed) + c.MealAllowances.Sum(ma => ma.AmountClaimed) + c

LINQ (L2E) with stored procedure and IQueryable

 ̄綄美尐妖づ 提交于 2019-12-13 06:23:42
问题 Consider a normal Linq expression will be something like this: (This is just a sample to make things more understandable) IQueryable<Person> personQuery= (from ppl in PersonContext select ppl).ASQueryable(); List<Person>personList = personQuery.where(x => x.age==13).ToList(); So if I decided to put the 1st part of the linq query inside a stored procedure, things will work out something like this. IQueryable<Person> personQuery= PersonContext.sp_RetrievePerson().ASQueryable(); List<Person>

Simple Linq-to-entities query involving .Include I believe

杀马特。学长 韩版系。学妹 提交于 2019-12-13 06:21:45
问题 I have a Linq-to-Entities query that is not complicated but requires an .include and/or projection and/or join because it must be executed in one pass. Here is my database (Microsoft SQL Server 2008): Table A (Customers) (contains CustomerID (customer IDs), and ZipCode (zip codes) as strings. Table C (Categories) (contains CategoryID (categories) like "food", "shelter","clothing", "housing" (primary keys). Table A_C is a linking table, since Tables A and C are linked as many-to-many: contains

Entity Framework: View exclusion without primary key

时光总嘲笑我的痴心妄想 提交于 2019-12-13 06:02:41
问题 I am using SQL Server where I have designed a view to sum the results of two tables and I want the output to be a single table with the results. My query simplified is something like: SELECT SUM(col1), col2, col3 FROM Table1 GROUP BY col2, col3 This gives me the data I want, but when updating my EDM the view is excluded because "a primary key cannot be inferred". With a little research I modified the query to spoof an id column to as follows: SELECT ROW_NUMBER() OVER (ORDER BY col2) AS 'ID',

Getting error “The parameter was not bound in the specified LINQ to Entities query expression.”

*爱你&永不变心* 提交于 2019-12-13 05:50:39
问题 I am trying to create a generic way to find deals that have a date that fall within a list of user-specified date ranges. Here's my code: var closeDates = new List<Range<DateTime>> {{ new Range<DateTime>{ Start = DateTime.Now, End = DateTime.Now.AddDays(1) }}; var deals = dbContext.Deals.AsQueryable(); deals = _helperService.ApplyDateRanges(deals, deal => deal.ClosedDate, closeDates); The _helperService method: public IQueryable<T> ApplyDateRanges<T>(IQueryable<T> query, Expression<Func<T,

How to simulate Derived table with linq to Entities

那年仲夏 提交于 2019-12-13 05:37:18
问题 How I can simulate Derived Table with linq? Consider this Code: SELECT * FROM (SELECT * FROM Mytbl) AS tmp WHERE tmp.ID=1 How I can write this with Linq ? thanks EDIT 1: How to convert this to linq?: select convert( decimal(10,1), ROUND(A.c2*100,8)), convert( decimal(10,1), ROUND(A.c3*100,8)) from ( SELECT ( SELECT CONVERT(INT, COUNT(ID)) FROM tbl WHERE (col06 >= @param_Min and col06 <= @param_Max ) ) / ( SELECT CONVERT(INT, COUNT(ID)) FROM tbl WHERE (col06 >= 10 ) ) as c2 ( SELECT CONVERT