linq-to-entities

Max value in Linq select Within Innerjoin

旧巷老猫 提交于 2019-12-24 18:13:31
问题 I have the following dilemma : We have two tables : Patient and Charges , patOID being foreign key within the Charges table. A simple join between 2 tables: from itemPat in listPat join itemCharge in listCharge on itemPat.patOID equals itemC.patOID select new { itemPat.patOID, itemCharge.paid } Considering the face that a patient can have more than 1 charges, how can I get the itemCharge for the biggest value of a certain field( ex. paid ) . What have i tried : from itemPat in listPat join

Optional navigation property is not being loaded

给你一囗甜甜゛ 提交于 2019-12-24 17:06:23
问题 I can't for the life of me figure out why Entity Framework (4.1, Code First) is not materializing an optional navigation property. POCOs: public class PlanMember { public Int64 Id { get; set; } public String FirstName { get; set; } public virtual SystemUser CaseManager { get; set; } public String LastName { get; set; } public virtual PlanMemberStatus Status { get; set; } } public class SystemUser { public String EMail { get; set; } public String FirstName { get; set; } public String Id { get;

Linq to Entity compare two string in Where clause

孤人 提交于 2019-12-24 14:51:35
问题 I've got an error: LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression. The piece of code: plist= plist.Where(p => Convert.ToInt(p.Period) >= syslockPeriod); p.Period example: 201206 pList is IQueryable . p.Period is string typed. sysLockPeriod is int. How to fix it? 回答1: LINQ to entities will try to translate Convert.ToInt32() into SQL instructions, because it's not one of the known methods it can

Entity framework - NotSupportedException in lambda expression

六眼飞鱼酱① 提交于 2019-12-24 10:49:21
问题 In my MVC application ApplicationUser and Employee classes have 1-1 relationship: public class ApplicationUser : IdentityUser { public Employee Employee { get; set; } } public class Employee { [Key] public virtual ApplicationUser ApplicationUser { get; set; } public virtual string Name { get; set; } } In a public static class I have following methods: public static ApplicationUser GetCurrentApplicationUser(string userName) { using (DbContext db = new DbContext()) { return db.Users

Populate a list property from delimited string

左心房为你撑大大i 提交于 2019-12-24 08:49:11
问题 This is kind of a simple application but I'm a bit new to ASP.NET MVC so I'm having a bit of trouble wrapping my head around how to accomplish this because the What I have are two classes: public class BugAssignment { public int BugAssignmentID { get; set; } public int BugNumber { get; set; } public int UserID { get; set; } public virtual User User { get; set; } } public class BugAssignmentList { public int BugAssignmentListID { get; set; } public string Name { get; set; } public List

EF Order by Nullable DateTime using string and nested reflection

核能气质少年 提交于 2019-12-24 08:39:27
问题 According to this question I have created my methods for ordering data sets. public static IOrderedQueryable<T> Order<T>(this IQueryable<T> source, string propertyName, ListSortDirection direction = ListSortDirection.Ascending) { return ListSortDirection.Ascending == direction ? source.OrderBy(ToLambda<T>(propertyName)) : source.OrderByDescending(ToLambda<T>(propertyName)); } private static Expression<Func<T, object>> ToLambda<T>(string propertyName) { var propertyNames = propertyName.Split('

Obtain ToTraceString() for IQueryable

廉价感情. 提交于 2019-12-24 08:38:39
问题 I use `..... ..... query = query.Where(criterion, fiedNames); string sql2 = ((ObjectQuery)query).ToTraceString();' to obtain and tweak SQL code that is going to be executed by LINQ. When I do quick watch I get the following SQL statement which i do not understand. SELECT [UnionAll2].[C3] AS [C1], [UnionAll2].[C4] AS [C2], [UnionAll2].[C5] AS [C3], [UnionAll2].[C6] AS [C4], [UnionAll2].[C7] AS [C5], [UnionAll2].[C8] AS [C6], [UnionAll2].[C9] AS [C7], ..... few hundereds line more..... @p__linq

Linq - How to store “where condition” in variable

我的梦境 提交于 2019-12-24 06:47:55
问题 its possible to store Where condition in this linq statement in variable? Func<NutritionValues, bool> condition; if (isBarcode) condition = f => f.barcode == name; else condition = f => f.food == name; var foods = context.NutritionValues.Where(condition). Select(f => new SerializableFood { Name = f.food, Calories = f.energy_kcal, Carbohydrates = f.carbohydrates, Fats = f.fats, Proteins = f.protiens }); Condition is 100% right. If I write condition f => f.barcode == name directly into the

OUTER JOIN not returning expected results in EF Core

心已入冬 提交于 2019-12-24 06:43:58
问题 In my ASP.NET MVC Core app the POST action method Test is not returning the expected results. The web app was created using this official ASP.NET Core site and was modified slightly. The real app can be downloaded from here and is using latest version of VS2015 . The app is using EF Core . If you download the project, you will need to do the following steps to test the above unexpected results: Note : Order of these steps is important. This is a very small test project. Step2 will create a

Best way for converting linq to entity query to strongly typed ObservableCollection

和自甴很熟 提交于 2019-12-24 05:42:29
问题 I am learning these days Entity Framework 5. I developing WPF application which based on MVVM and PRISM. In order to get property changed notifications I am using ObservableCollection for keep my data. I have problem when I use linq to entity projection and I am not sure what is the best solution for it. As you know, when you execute projection through linq to entity you get anonymous type that no one know out the scope of the method. I searched how to make this query strongly typed. I seen