ef-core-5.0

The LINQ expression 'OUTER APPLY Projection Mapping in EF .NET Core 5 Exception

拜拜、爱过 提交于 2021-02-11 17:35:42
问题 After migrating from .NET Core 2.x to .NET Core 5.0, we are facing this problem. Error: (Added as a CODE for better readability) The LINQ expression 'OUTER APPLY Projection Mapping: ( SELECT e0.Id, e0.FirstName, e0.MiddleName, e0.LastName FROM Employees AS e0 WHERE (((e0.Status != 4) && EXISTS ( Projection Mapping: SELECT 1 FROM FunctionRoles AS f0 WHERE t.Id == f0.SchoolId)) && (e0.FunctionRoleId == (Projection Mapping: EmptyProjectionMember -> 0 SELECT TOP(1) f1.Id FROM FunctionRoles AS f1

Migrating One-to-Many to Many-to-Many with the new EF Core 5.0

谁说我不能喝 提交于 2021-02-11 14:22:38
问题 I have an ASP.NET Core 5 project (migrated from ASP.NET Core 3.1). The project uses EF Core. EF Core 5 has built-in support for Many-to-Many. The main reason I first migrated from 3.1 to 5.0. Now my project has a One-to-Many relationship, which I want to convert to a Many-to-Many. Is such a relationship migration possible? Current code: public class File { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption

Violation of PRIMARY KEY constraint 'PK_XY'. Cannot insert duplicate key in object 'dbo.XY'

自作多情 提交于 2021-02-11 08:23:44
问题 Using EF Core, I have a Zone that can have multiple Sol (soils), same Sol can be attached to multiple Zone : public class Sol { // ... public ICollection<Zone> Zones { get; set; } = new List<Zone>(); } public class Zone { // ... public ICollection<Sol> Sols { get; set; } = new List<Sol>(); } public override void Configure(EntityTypeBuilder<Zone> builder) { // ... builder .HasMany(p => p.Sols) .WithMany(p => p.Zones); } When adding my Sols to a Zone however I get the following exception:

Get the table name when configuring an entity

我的梦境 提交于 2021-02-08 11:38:02
问题 EF Core: I need to get the name of the table as the name of the entity, not dbset, also, I need the Id to be "tableName"+"Id" . I have a DbSet<Country> Countries - I need table name Country and Id column (inherited from base entity) to be CountryId . I started with this code that works: foreach (var entity in modelBuilder.Model.GetEntityTypes()) { var builderEntity = modelBuilder.Entity(entity.Name); // make table name to be entity name builderEntity.ToTable(entity.DisplayName()); // make Id

Get the table name when configuring an entity

孤街浪徒 提交于 2021-02-08 11:35:59
问题 EF Core: I need to get the name of the table as the name of the entity, not dbset, also, I need the Id to be "tableName"+"Id" . I have a DbSet<Country> Countries - I need table name Country and Id column (inherited from base entity) to be CountryId . I started with this code that works: foreach (var entity in modelBuilder.Model.GetEntityTypes()) { var builderEntity = modelBuilder.Entity(entity.Name); // make table name to be entity name builderEntity.ToTable(entity.DisplayName()); // make Id

InvalidCastException after upgrading to EF Core 5.0

时光总嘲笑我的痴心妄想 提交于 2021-01-29 07:05:28
问题 I've just upgraded my project from .NET Core 3.1 to .NET 5.0 and updating all packages to the latest version. All built fine, but now I'm having trouble loading some entities, getting this error: Unable to cast object of type 'Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader' to type 'Microsoft.Data.SqlClient.SqlDataReader'.' I'm not certain, but I have a couple of entities which have an Address property which is an [Owned] type which has a NetTopologySuite.Geometries.Point

Change name of generated Join table ( Many to Many ) - EF Core 5

旧城冷巷雨未停 提交于 2021-01-27 07:10:20
问题 How to change name of a join table that EF Core 5 Created ? for example public class Food { public int FoodId { get; set; } public string Name { get; set; } public string Description { get; set; } public string Ingredients { get; set; } public string PhotoPath { get; set; } public ICollection<Menu> Menus { get; set; } } public class Menu { public int MenuId { get; set; } [Column(TypeName = "date")] public DateTime MenuDate { get; set; } public bool IsPublished { get; set; } public ICollection

Change name of generated Join table ( Many to Many ) - EF Core 5

99封情书 提交于 2021-01-27 07:08:01
问题 How to change name of a join table that EF Core 5 Created ? for example public class Food { public int FoodId { get; set; } public string Name { get; set; } public string Description { get; set; } public string Ingredients { get; set; } public string PhotoPath { get; set; } public ICollection<Menu> Menus { get; set; } } public class Menu { public int MenuId { get; set; } [Column(TypeName = "date")] public DateTime MenuDate { get; set; } public bool IsPublished { get; set; } public ICollection