entity-framework

In clause in linq expression

允我心安 提交于 2020-03-06 09:11:29
问题 i am developing a online test application where have two tables category and subCategory from which i want to select some questions with the help of category and subcategory. something like ( question where category ID in (1) and subcategoryID in (1,2,3,4) I am getting list of subcategory that is going to pass in query int[] subCategoryForQuestions=new int[]{1,2,3,4}; var TestDataList = coreDbContext.SolutionMasters .Where(x => x.CategoryID == categoryID && x.DifficultyId == questionLevel &&

In clause in linq expression

﹥>﹥吖頭↗ 提交于 2020-03-06 09:05:36
问题 i am developing a online test application where have two tables category and subCategory from which i want to select some questions with the help of category and subcategory. something like ( question where category ID in (1) and subcategoryID in (1,2,3,4) I am getting list of subcategory that is going to pass in query int[] subCategoryForQuestions=new int[]{1,2,3,4}; var TestDataList = coreDbContext.SolutionMasters .Where(x => x.CategoryID == categoryID && x.DifficultyId == questionLevel &&

Perfomance issue - .Count in MVC view

萝らか妹 提交于 2020-03-06 07:35:31
问题 For several pages I use a .Count inside a foreach loop @model ICollection<Item> foreach(var item in Model) { @item.Flight.FlightReservations.count } Because of lazy loading the EF makes a round trip to the database for this. Now I want to fix this by using this or linq version: Include("List.Flight.FlightReservations") Doing this makes loading my dbSet take even longer than those foreach round trips How can I 'load' parts of only 1 object? I would like to use context.Items.Single(p => p.id ==

How can I build logic upon supplied logic in a LINQ-to-Entities Where expression?

我的梦境 提交于 2020-03-06 07:28:04
问题 I often come across, in LINQ for Entity Framework, a pattern where I add a .Where clause if a string value is specified, like: IQueryable<Foo> query = Foos.AsQueryable() if (!string.IsNullOrWhitespace(nameFilter)) query = query.Where(x => x.Name == name); if (!string.IsNullOrWhitespace(addressFilter) != null) query = query.Where(x => x.Address == addressFilter ); if (!string.IsNullOrWhitespace(cityFilter) != null) query = query.Where(x => x.City == cityFilter ); // ... I wanted to clean this

How to check if object is null in EF

依然范特西╮ 提交于 2020-03-06 06:22:36
问题 I am new to EF and trying to do a small project with it. I added a condition to EF but I am having a problem. My condition is all about IN condition like SQL, SELECT * FROM table1 WHERE col1 IN (1,2,3...) Here is my EF.... var res3 = res2.Where(l => !slitDetail .Any(s => s.BlockId == l.Id && s.WarehouseDepot.WarehouseDepotName != "Ara Ürün Depo" && s.WarehouseDepot.WarehouseDepotName != "Özel Kesim Depo")); s.WarehouseDepot might be NULL sometimes which is normal, but if it is null, this

Transform SQL Select to Entity Framework Join across five tables

淺唱寂寞╮ 提交于 2020-03-06 03:27:31
问题 I start to use Entity Framework in a new project, to see if it is valid or no. But I got stuck in a part where I need to join 5 tables. I am pretty sure that the relationship between them are ok, I can select using .Include(x => x.table) for only three (because I found on the internet), and I know I will need to Use Join() , but I don't know how. The select in SQL is: SELECT Module.* FROM UserGroup as ug INNER JOIN Group as g ON ug.IdGroup = g.IdGroup INNER JOIN GroupFunctionality as gf ON g

Can't insert simple row into DB2 w/ EF5

纵然是瞬间 提交于 2020-03-06 02:37:29
问题 I'm using EF5 and DB2 9.1 for z/OS and the IBM data provider. Everything in my program works fine except for this one part. I can't insert a new object into the database. I get the error: {"ERROR [23502] [IBM][DB2] SQL0407N Assignment of a NULL value to a NOT NULL column \"EMPL_ID\" is not allowed."} I have verified time after time that the value is NOT null... it's a valid integer. What's going on? if (String.IsNullOrEmpty(emplID)) return null; try { int _emplID = Convert.ToInt32(emplID.Trim

Can't insert simple row into DB2 w/ EF5

不想你离开。 提交于 2020-03-06 02:37:08
问题 I'm using EF5 and DB2 9.1 for z/OS and the IBM data provider. Everything in my program works fine except for this one part. I can't insert a new object into the database. I get the error: {"ERROR [23502] [IBM][DB2] SQL0407N Assignment of a NULL value to a NOT NULL column \"EMPL_ID\" is not allowed."} I have verified time after time that the value is NOT null... it's a valid integer. What's going on? if (String.IsNullOrEmpty(emplID)) return null; try { int _emplID = Convert.ToInt32(emplID.Trim

Group by Inside Group by Using EntityFramwork in Mvc5

大憨熊 提交于 2020-03-05 05:12:18
问题 Hi guys I am trying I try to bring the count for each male and female by age As in the table here I was able to calculate all ages but I can not count the ages as boys and girls. I want help, please here is my code in controller public ActionResult AllCuont() { var query = (from t in db.Pations let range = ( t.Age>= 1 && t.Age < 5 ? "age from 1 to 4" : t.Age >= 5 && t.Age < 15 ? "age from 5 to 14" : t.Age >= 15 && t.Age < 25 ? "age from 15 to 24" : t.Age >= 25 && t.Age < 45 ? "age from 25 to

no-build prevents the scaffolding process from being performed?

非 Y 不嫁゛ 提交于 2020-03-05 04:11:10
问题 My textbook says: dotnet ef dbcontext scaffold "Server (localdb)\MSSQLLocalDB;Database=XXX" "Microsoft.EntityFrameworkCore.SqlServer" --output-dir "Models/Scaffold" --context ScaffoldContext --force --no-build --no-build argument prevents the project from being built before the scaffolding process is performed. It is easy to get into a situation where the scaffolding process generates a data model that is out of sync with the rest of the application, such as controllers and views. Entity