entity-framework-core

How to insert graph in Entity Framework with circular dependency

北城以北 提交于 2020-06-28 06:09:11
问题 This is how database structure looks like: Vehicle has lot of CanNetworks and each CanNetwork has lot of ECUs . And that would save perfectly if that was only I have. But, each vehicle also has one special ECU called gatewayECU so problem happens with saving because entity framework core does not know how to handle that scenario. It needs to insert vehicle before inserting ecus, but how to insert vehicle when ecu is not inserted. This is what I tried: ignore (delete, invalidate) gatewayecu

Equivalent of ValidateEntity in Core3.0

ⅰ亾dé卋堺 提交于 2020-06-28 06:01:53
问题 It seems protected override DbEntityValidationResult ValidateEntity is removed from IdentityDbContext class in packages ( Microsoft.AspNetCore.Identity.EntityFrameworkCore) in latest versions (2.2.0 and 3.0) How can I validate database in Core 3.0 or Core 2.2? 回答1: I know that it was a long time ago but I hope it helps people with futures issues with this topic like me, I was checking how to do it from Asp.net core 2.2 and I Found this Issue in GitHub. https://github.com/dotnet/efcore/issues

Entity Framework Core - efficient way to update Entity that has children based on JSON representation of entity being passed in via Web API

天涯浪子 提交于 2020-06-28 03:43:22
问题 I am writing an .NET Core Web API which is backed by Entity Framework Core and having a PostgreSQL database underneath (AWS Aurora). I have been able to learn and successfully work with EF Core for inserts and querying data, which is great, but starting to look into UPDATES of existing entities and it's become unclear to me the most efficient way to achieve what I'm after. I have my Database Entities as a result of my Database First scaffolding exercise. I have an entity that is similar to

Transient Failure handling in .net core 2.1 MVC for MySQL Database

六眼飞鱼酱① 提交于 2020-06-27 17:17:25
问题 services.AddDbContext<MyContext>(options => { options.UseSqlServer(mysqlConnection, sqlServerOptionsAction: sqlOptions => { sqlOptions.EnableRetryOnFailure( maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); }); }); I found this code snippet at: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/implement-resilient-entity-framework-core-sql-connections My DB is MySQL 5.7 I changed the above code to :

Possible to call a stored procedure on a Table-Per-Hierarchy table in EF Core 3.1?

僤鯓⒐⒋嵵緔 提交于 2020-06-27 16:46:09
问题 I'm moving from EF Core 2.2 to 3.1. One breaking change (#15392) was that it no longer composed over stored procedures, so you had to add 'AsEnumerable'. That usually works, but I have a stored procedure call on a TPH table where that fails: My call to the SPROC is: SqlParameter authorizedUserID_p = new SqlParameter("@authorizedUserID", authorizedUser.ID); IEnumerable<Post> query = context.Posts.FromSqlRaw<Post>("Post.USP_ReadPost @ID, @AuthorizedUserID", parameters: new[]{ parentID_p,

EF Core GroupBy with Select Distinct Count

放肆的年华 提交于 2020-06-27 16:05:29
问题 I have a table, Items , which has a many to one relationship with two distinct parents. I want to select the counts of ParentA for each ParentB . In SQL this is simple: SELECT "ParentBId", count(distinct "ParentAId") FROM "Items" GROUP BY "ParentBId" In Linq I have this statement: var itemCounts = await _context.Items .GroupBy(item => item.ParentBId, (parentBId, items) => new { ParentBId = parentBId, Count = items.Select(item => item.ParentAId).Distinct().Count(), }).ToDictionaryAsync(group =

How to fix 'Method 'get_Info' in type 'Oracle.EntityFrameworkCore does not have an implementation.'

☆樱花仙子☆ 提交于 2020-06-27 07:11:08
问题 I'm trying to connect to Oracle DB via EW. On method OnConfiguring is error: System.TypeLoadException: 'Method 'get_Info' in type 'Oracle.EntityFrameworkCore.Infrastructure.Internal.OracleOptionsExtension' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.' public class Template { public int Id { get; set; } public string Info { get; set; } } class TemlateContext : DbContext { public DbSet<Template>

EF Core lazy loading proxies return null randomly instead of entities

被刻印的时光 ゝ 提交于 2020-06-26 16:23:26
问题 I have a .Net Core 3.1 application with an SQL database. I use lazy-loading proxies to automatically retrieve data from related tables. Basically, I have a table, which references some other entities via 1-to-many or 1-to-1 relation. Thing is, most of the cases, every relation is OK, every entity is loaded and I can read it's properties (name field, for example). But, in very specific cases, those entities won't load , although relation Id is there. It looks like this: Model is like this:

Entity framework core: Cannot insert explicit value for identity column in table 'Relation' when IDENTITY_INSERT is set to OFF

孤人 提交于 2020-06-25 22:03:26
问题 I'm bulding an application and when I want to insert a form into my form table I get the following error: Cannot insert explicit value for identity column in table 'Relation' when IDENTITY_INSERT is set to OFF. These are my models: Form model: [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [ForeignKey("FormType")] public int? TypeId { get; set; } public virtual FormType Type { get; set; } [ForeignKey("FormStatusType")] public int? StatusTypeId { get; set; }

Entity Framework Core and SQL Server 2016 temporal tables

时光总嘲笑我的痴心妄想 提交于 2020-06-25 10:00:29
问题 We are using EF Core and SQL Server 2016 for our .NET Core Web API. I am evaluating use of temporal tables and its impact on EF Core code. When I generate the EF model using cmdline then it generates model with appstart, append and mappings in dbcontext . When I do insert/update they fail saying these columns cannot be updated. I had to remove appstart, end from model and dbcontext mapping to make it work. I read there is no interception capability yet in EF Core like EF 6.x. Please advise