entity-framework-core

There is no argument given that corresponds to the required formal parameter 'options'

不羁岁月 提交于 2019-12-20 01:34:32
问题 I'm working on my first application in .Net Core. I'm getting this build error for some reason: Error CS7036 There is no argument given that corresponds to the required formal parameter 'options' of 'LakeViewContext.LakeViewContext(DbContextOptions<LakeViewContext>)' LakeView I wasn't able to find a solution through Google Search or MS documentation. My Context class: using LakeView.Models; using Microsoft.EntityFrameworkCore; namespace LakeView { public class LakeViewContext : DbContext {

EF Core enable Lazy Loading conditionally

南楼画角 提交于 2019-12-20 01:03:58
问题 I am looking for a possible way to enable Lazy Loading in my DbContext but not all the time, only in specific instances when I need it. Because of issues like the N+1 queries with large datasets and JSON serialization traversing object properties and serializing my entire database I usually do not want Lazy Loading. However, in some instances I do want it. When generating reports I load a top-level object and many child objects in order to populate the report fields. Due to the nature of the

EF Core 2.0.0 One to One-or-Zero with Fluent Api

这一生的挚爱 提交于 2019-12-19 23:21:39
问题 In Fluent Api at EF Core 2.0.0 , there aren't any methods HasRequired and HasOptional , and i have tow Models, Person and Employee: public class Person { public int Id { get; set; } public int EmployeeId { get; set; } public virtual Employee Employee { get; set; } // Optional } public class Employee { public int Id { get; set; } public int PersonId { get; set; } public virtual Person Person {get; set; } // Required } Person May to have Employee: Optional Employee Should have Person: Required

Entity Framework Core - Take(1), Single(), First()… Not Working with Oracle Provider (ORA-00933: SQL command not properly ended)

我只是一个虾纸丫 提交于 2019-12-19 18:56:11
问题 I'm using ef core(2.2.4) with oracle database oracleProvider: Oracle.EntityFrameworkCore(2.18.0-beta3) this code: IQueryable<KeyInfo> queryable = context .KeyInfos .Where(x => x.MobileNumber == "989191111111") .Take(1); generate this db query: SELECT "x"."ID", "x"."Key", "x"."MobileNumber", "x"."NationalCode" FROM "KeyInfo" "x" WHERE "x"."MobileNumber" = N'989191111111' FETCH FIRST 1 ROWS ONLY; running query give me this error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL

.NET CORE 2 EF Include

穿精又带淫゛_ 提交于 2019-12-19 18:29:21
问题 I am using new .net core and EF. I need help with include linq command. I have some 1:N models and if the collection contais some data marked like deleted I do not want to include them. How to do it? var company = await _context.Company .Include(y => y.Administrators) .Include(y => y.CompanyPartTimers) .Include(z => z.WorkPlaces) .Include(z => z.Requirements) .FirstAsync(x => x.Id == id); If I add the condition .Include(z => z.WorkPlaces).Where(x=>x.WorkPlaces.Where(x=>!x.IsDeleted)) It doesn

The property 'x' is not a navigation property of entity type 'y'

时光总嘲笑我的痴心妄想 提交于 2019-12-19 14:59:50
问题 I'm using EF Core with ASP Core 2.0. Using latest Identity framework. I get this exception on page All. InvalidOperationException: The property 'User' is not a navigation property of entity type 'Gallery'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names. ApplicationUser looks like: public class ApplicationUser : IdentityUser<Guid> { public ICollection<Gallery> Galleries { get; set; } } Entity Gallery looks like: public class Gallery {

The property 'x' is not a navigation property of entity type 'y'

◇◆丶佛笑我妖孽 提交于 2019-12-19 14:59:47
问题 I'm using EF Core with ASP Core 2.0. Using latest Identity framework. I get this exception on page All. InvalidOperationException: The property 'User' is not a navigation property of entity type 'Gallery'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names. ApplicationUser looks like: public class ApplicationUser : IdentityUser<Guid> { public ICollection<Gallery> Galleries { get; set; } } Entity Gallery looks like: public class Gallery {

MVC Routing template to represent infinite self-referential hierarchical category structure

大城市里の小女人 提交于 2019-12-19 10:36:11
问题 I have a product category table to represent a hierarchical category structure, a typical Parent-Child relationship table in the database. Fill it with Guitar Center's data as an example: If you render them to a page with <ul> and <li> : Texts in blue are the URLs I would like to generate. For any given category, the link consists of its slug and its parents' slugs. Note that the example I listed only has 2 parent-child levels. In theory, with the self-referential structure, any child could

Change MigrationsHistoryTable column names in EF Core

我的梦境 提交于 2019-12-19 10:22:47
问题 I have a standardized all table and column names in my EF Core database to use snake_case. I was able to change the migrations history table name and schema to match the rest of the database, but I am not able to find a way to change the columns from MigrationId to migration_id and ProductVersion to product_version . Any ideas on how this could be done? 回答1: Here is an example of how to do it on SQL Server. First, create a custom implementation of SqlServerHistoryRepository overriding

No nested results in Entity Framework Core [duplicate]

隐身守侯 提交于 2019-12-19 10:18:12
问题 This question already has an answer here : EF Core returns null relations until direct access (1 answer) Closed 2 years ago . i have a strange behavior in C# with EF It's a .NET Core project with EF Core 1.1.0 "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", I've created two Models, "User" and "Group" public class User { public int Id { get; set; } public string name { get; set; } public string lastName { get; set; } public