entity-framework-core

EF Core 2.2, owned entities generated as another table when multiple in hierarchy

不想你离开。 提交于 2021-02-08 17:26:55
问题 I have a model with a class Address marked [Owned] and a hierarchy of people (person, customer or employee, then even more subtypes etc). There are addresses at different stages of this hierarchy and all of it ends up in one table as EF Core is limited to table per hierarchy. I expected all the attributes from address to appear multiple times in that person table (once per mention in any of the subtypes) however it doesn't appear at all! Instead i see FK for each of them and a separate

EF Core 2.2, owned entities generated as another table when multiple in hierarchy

那年仲夏 提交于 2021-02-08 17:25:05
问题 I have a model with a class Address marked [Owned] and a hierarchy of people (person, customer or employee, then even more subtypes etc). There are addresses at different stages of this hierarchy and all of it ends up in one table as EF Core is limited to table per hierarchy. I expected all the attributes from address to appear multiple times in that person table (once per mention in any of the subtypes) however it doesn't appear at all! Instead i see FK for each of them and a separate

Transaction between contexts

喜夏-厌秋 提交于 2021-02-08 13:45:26
问题 I'm developing a Console Application using Entity Framework Core (7). The application is divided into 3 different areas but the database is shared. I created 3 different DbContext and now I need to perform a transaction between all of them. So I need an atomic operation the save all the changes or nothing (rollback). I know that in entity frameowrk 6 there was a class called TransactionScope but I cant find an alterntive in EF Core. Using the following code: public static void Main(string[]

How do I get an IDbTransaction from an IDbContext?

允我心安 提交于 2021-02-08 13:16:41
问题 An IDbContext has a DatabaseFacade , which has a CurrentTransaction property. But the CurrentTransaction is an IDbContextTransaction . I want to pass an IDbTransaction to Dapper. How do I get an IDbTransaction instead of an IDbContextTransaction ? 回答1: Currently (up to latest at this time EF Core 2.0) there is no official way to do that. But you can use the following custom extension method to get it from IDbContextTransaction : using Microsoft.EntityFrameworkCore.Infrastructure; using

Azure function V3 could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1

梦想与她 提交于 2021-02-08 13:08:49
问题 Case We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection 1) DependecyInjection [assembly: FunctionsStartup(typeof(xxxxx.Startup))] namespace xxxxx { public class Startup : FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { var services = builder.Services; var configBuilder = new ConfigurationBuilder() .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("local.settings.json", true, reloadOnChange: true)

Define relationship in EF Core

亡梦爱人 提交于 2021-02-08 12:11:24
问题 How do I define the relationships here with EF Core? I have an Employee table which has multiple Jobs public class Employee { public int EmployeeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public List<HourlyRate> DefaultRate { get; set; } public string Note { get; set; } public bool Active { get; set; } public DateTime DateHired { get; set; } public List<PhoneNumber> PhoneNumbers { get; set; } public List<Address> Addresses { get; set; } public

Define relationship in EF Core

ぐ巨炮叔叔 提交于 2021-02-08 12:10:23
问题 How do I define the relationships here with EF Core? I have an Employee table which has multiple Jobs public class Employee { public int EmployeeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public List<HourlyRate> DefaultRate { get; set; } public string Note { get; set; } public bool Active { get; set; } public DateTime DateHired { get; set; } public List<PhoneNumber> PhoneNumbers { get; set; } public List<Address> Addresses { get; set; } public

UpdateRange method of Entity Framework Core does not work

房东的猫 提交于 2021-02-08 11:54:17
问题 The UpdateRange method of Entity Framework Core is used here to update multiple records but it is not working. My code is: var dept1 = new Department() { Id = 8, Name = "New Designing" }; var dept2 = new Department() { Id = 9, Name = "New Research" }; var dept3 = new Department() { Id = 102, Name = "New HR" }; List<Department> modifiedDept = new List<Department>() { dept1, dept2, dept3 }; using (var context = new CompanyContext()) { context.UpdateRange(modifiedDept); await context

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