linq-to-entities

Build Lambda Expressions with Contains

馋奶兔 提交于 2020-08-26 00:04:51
问题 I have a problem converting simple linq query to Lambda Expression. My queries look like this: int[] array = List<int> array2 = sql.OfType<Table1>().Select(x=>x.ID).Take(10).ToList(); var result = sql.OfType<Table1>().Where(x => array.Contains(x.ID)).Take(10).ToList(); and the final result should be: static void DynamicSQLQuery<T>(IQueryable<T> sql, string fieldName) { List<int> array = sql.OfType<T>().Select(SelectExpression<T>(fieldName)).Take(10).ToList(); var result = sql.OfType<T>()

Group join in EF Core 3.1

冷暖自知 提交于 2020-08-19 07:29:29
问题 I am trying to group join in EF core 3.1 the problem it returns Processing of the LINQ expression 'DbSet failed. This may indicate either a bug or a limitation in EF Core my code is like this var employees = await (from enrollment in RepositoryContext.Enrollments join allowance in RepositoryContext.Allowances.Include(y=>y.AllowanceType) on enrollment.EmployeeId equals allowance.EmployeeId into allowances select new { enrollment, allowances } ).AsNoTracking().ToListAsync(); the allowances is

How can I convert a custom function to a sql expression for Entity Framework Core 3.1

為{幸葍}努か 提交于 2020-08-10 20:21:49
问题 I am looking for some guidance/help on how to approach my problem as I'm running out of ideas. I am trying to take a custom extension function and pass it to the database via Entity Framework (EF Core 3.1) using Linq to Entities but I am getting a "{method} could not be translated" error regardless of what I do. I have tried using HasDbFunction along with HasTranslation using this link Thinktecture - Entity Framework Core - Custom Functions (using HasDbFunction) to no avail. I have also tried

Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship

馋奶兔 提交于 2020-07-06 09:06:56
问题 I have an entity with a foreign key relationship to an asp.net membership provider users table. This portion of the model looks like this: I can't seem to assign the foreign key relationship when inserting the Users table record, the record containing the foreign key to the aspnet_Users table. I keep getting the error: An item with the same key has already been added. The code I'm using looks like: UserAdmin userToAdd = new UserAdmin(); ... userToAdd.aspnet_Users = membershipUser; //line

The method 'Skip' is only supported for sorted input in LINQ to Entities

自古美人都是妖i 提交于 2020-06-10 02:19:14
问题 What could be causing this problem? public ActionResult Index(int page = 0) { const int pageSize = 3; var areas = repo.FindAllAreas(); var paginatedArea = new PaginatedList<Area>(areas, page, pageSize); return View(paginatedArea); } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UTEPSA.Controllers { class PaginatedList<T> : List<T> { public int PageIndex { get; private set; } public int PageSize { get; private set; } public int TotalCount { get

LINQ is Generating Extra IS NULL Condition in SQL Statement

巧了我就是萌 提交于 2020-05-10 04:12:59
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((

LINQ is Generating Extra IS NULL Condition in SQL Statement

本秂侑毒 提交于 2020-05-10 04:12:30
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((