entity-framework-core

Entity Framework Core Many to Many change navigation property names

若如初见. 提交于 2020-12-26 10:22:48
问题 I have a table called "LogBookSystemUsers" and I want to setup many to many functionality in EF Core 5. I almost have it working but the problem is my ID columns are named SystemUserId and LogBookId but when EF does the join it tries to use SystemUserID and LogBookID . This is my current configuration code: modelBuilder.Entity<SystemUser>() .HasMany(x => x.LogBooks) .WithMany(x => x.SystemUsers) .UsingEntity(x => { x.ToTable("LogBookSystemUsers", "LogBooks"); }); I tried this: modelBuilder

How to insert an existing IQueryable element to a ThenInclude method in EF Core

血红的双手。 提交于 2020-12-26 08:42:06
问题 How do I insert an existing IQueryable element in a ThenInclude method? public IQueryable<Store> Store => GetDbSet<Store>() .Include(st => st.App) .ThenInclude(app => app.Client) .ThenInclude(cl => cl.Country) .ThenInclude(co => co.Culture) .Include(st => st.Features) .ThenInclude(this.StoreFeatures); public IQueryable<StoreFeatures> StoreFeatures => GetDbSet<StoreFeatures>() .Include(ft => ft.Cultures) .ThenInclude(ct => ct.Culture); 回答1: Interesting question. The problem is that Include /

Entity Framework: Get the DataType of Metadata IProperty

喜欢而已 提交于 2020-12-15 06:14:49
问题 How do I find the DataType of Metadata.IProperty in Entity Framework Core? var tableType = _dbContext.Model.GetEntityTypes().First(c => c.GetTableName() == tableName); foreach (var property in tableType.GetProperties()) { var test = property.PropertyInfo.PropertyType.Name; Using property.PropertyInfo.PropertyType.Name , sometimes works, however for nullable objects it prints null. I am looking for a clean way to get data type. 回答1: The Type of the IProperty is represented by ClrType property.

NU1107: Version conflict detected for Microsoft.EntityFrameworkCore.Abstractions. Installing EFCore for use with AspNetCore 2.2

一曲冷凌霜 提交于 2020-12-15 05:23:24
问题 I was able to upgrade my .NetStandard2.0 project to use EntityFrameworkCore 3.1.4 and created a nuget package. Now I want to use that nuget package in my netcoreapp2.2 project. However, when I try to add the package via nuget I get Error NU1107 Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference Microsoft.EntityFrameworkCore 3.1.4 directly to project MyApi to resolve this issue. MyApi -> SBDSTD.Standard 1.0.0-CI-20200526-230146 -> Microsoft.EntityFrameworkCore (>= 3

NU1107: Version conflict detected for Microsoft.EntityFrameworkCore.Abstractions. Installing EFCore for use with AspNetCore 2.2

走远了吗. 提交于 2020-12-15 05:22:30
问题 I was able to upgrade my .NetStandard2.0 project to use EntityFrameworkCore 3.1.4 and created a nuget package. Now I want to use that nuget package in my netcoreapp2.2 project. However, when I try to add the package via nuget I get Error NU1107 Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference Microsoft.EntityFrameworkCore 3.1.4 directly to project MyApi to resolve this issue. MyApi -> SBDSTD.Standard 1.0.0-CI-20200526-230146 -> Microsoft.EntityFrameworkCore (>= 3

How to Create Drop-Down-List from Database in (Asp.net Core - MVC)?

我只是一个虾纸丫 提交于 2020-12-15 04:38:04
问题 I have 2 models: News Model TypeOfNew Model with (one to many relationship), every (TypeOfNew) has one or multiple news. News Model: public class News { [Required(ErrorMessage = "ID إجباري.")] [Key] public int ID { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display(Name = "عنوان الخبر")] public string Title { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display(Name = "مصدر الخبر")] public string Source { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display

How can we handle more than one user usage for identity core usermanagement and userstore without customization with generic type?

两盒软妹~` 提交于 2020-12-15 03:56:20
问题 We have a multitenant architecture with more than one user like below with identity core library: public class ApplicationUser : IdentityUser { } public class Tenant1User: ApplicationUser { public int deneme { get; set; } } public class Tenant2User: ApplicationUser { public string City { get; set; } public string Picture { get; set; } public DateTime? BirthDay { get; set; } public int Gender { get; set; } } We wanted to use UserManager generically in controllers constructors when injecting

Reading connection string placed in ASP.NET Core from class library. Database First

只谈情不闲聊 提交于 2020-12-13 04:34:25
问题 The structure of projects looks like this: Cars (ASP.NET Core MVC. Here we have a connection string ) Cars.Persistence (ASP.NET Core Class library. Here we have Repository, Database First) I've created a Model by the following command from this msdn docs: Scaffold-DbContext "Server=PC\SQL2014XP;Database=Cars;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models So far so good. However, now carsContext has hard coded connection string in Cars.Persistence - ASP.NET

Reading connection string placed in ASP.NET Core from class library. Database First

人走茶凉 提交于 2020-12-13 04:34:25
问题 The structure of projects looks like this: Cars (ASP.NET Core MVC. Here we have a connection string ) Cars.Persistence (ASP.NET Core Class library. Here we have Repository, Database First) I've created a Model by the following command from this msdn docs: Scaffold-DbContext "Server=PC\SQL2014XP;Database=Cars;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models So far so good. However, now carsContext has hard coded connection string in Cars.Persistence - ASP.NET

Entity Framework Core 3.1 with Temporal Tables - Access SysStartTime and SysEndTime

家住魔仙堡 提交于 2020-12-13 03:13:35
问题 I have created temporal tables based on Microsoft SQL Docs Creating a temporal table with a default history table . https://docs.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table?view=sql-server-ver15#creating-a-temporal-table-with-a-default-history-table Migration: public partial class Temporaltables : Migration { List<string> tablesToUpdate = new List<string> { "Images", "Languages", "Questions", "Texts", "Medias", }; protected override void Up