entity-framework-core

Query Interception - Disposing of diagnostic listeners

大城市里の小女人 提交于 2020-01-24 15:48:10
问题 We are using DiagnosticListeners in order to modify the SQL command text that EF Core produces. The problem is that our listeners need to be modifying the SQL command based on some user specific data that comes into our Api via HttpRequests. Our current solution is extremely hacky and likely to cause issues in the future. We register a new listener each time DbContext is created: public class MyContext : DbContext { private readonly HReCommandAdapter _adapter; public MyContext

.net standard class library - not support Distributed Transaction error

て烟熏妆下的殇ゞ 提交于 2020-01-24 15:29:06
问题 I developed a logging service in .net standard class library project. It is perfectly working without System.Transaction (TransactionScope class) . When I add transaction to a process, logger insert method throws an exception. [ This platform does not support distributed transactions. ] When I add code to core console app with System.Transaction it works. Is .net standard not supporting System.Transaction(TransactionScope)? NOTE: For now : .net core and nugets are lastest. Distribution

Entity Framework - Azure Table Storage Provider - Enum Support

泪湿孤枕 提交于 2020-01-24 13:19:44
问题 I am actually using the Azure Storage Table provider for EF (EntityFramework.AzureTableStorage 7.0.0-beta1). I've ended up how to configure the DbContext: public class Subscription { public string Environment { get; set; } public string Name { get; set; } ... ... } public class EF7Context : DbContext { public DbSet<Subscription> Subscriptions { get; set; } protected override void OnConfiguring(DbContextOptions options) { options.UseAzureTableStorage("MyconnectionString"); } protected override

Entity Framework Core - Multiple one-to-many relationships between two entities

烂漫一生 提交于 2020-01-24 10:58:46
问题 I have two entities - Team and Game . A team can have many games (One-To-Many). So that would look something like this: public class Team { public int Id { get; set; } public string Name { get; set; } public ICollection<Game> Games { get; set; } } public class Game { public int Id { get; set; } public DateTime Date { get; set; } public int TeamId { get; set; } public Team Team { get; set; } } This works nice, but I want to make it a little more refined by splitting the games into two

Foreign key with composite key in EF Core

巧了我就是萌 提交于 2020-01-24 10:17:30
问题 I have the following classes: public class ProductAttribute { public Guid ProductId { get; set; } public Guid AttributeId { get; set; } public List<ProductAttributeValue> Values { get; set; } public object[] GetKeys() { return new object[] {ProductId, AttributeId}; } } public class Product { public Guid Id { get; set; } public string Name { get; set; } } public class Attribute { public Guid Id { get; set; } public string Name { get; set; } } public class ProductAttributeValue { public Guid Id

Execute stored procedure in EF Core 3.0 vs 2.2

本小妞迷上赌 提交于 2020-01-24 03:56:29
问题 I am trying to update my code to accommodate changes in EF Core 3.0, specifically the deprecation of ExecuteSqlCommand . The following code was working in 2.2 but as stated, I need to get rid of ExecuteSqlCommand : SqlParameter srcid = new SqlParameter("@srcCharacterId", participantApplication.CharacterId); SqlParameter newid = new SqlParameter("@newCharacterId", newCharacterId); SqlParameter pResult = new SqlParameter { ParameterName = "@pResult", SqlDbType = System.Data.SqlDbType.Bit,

Why the database data is not being updated but object did and without error?

﹥>﹥吖頭↗ 提交于 2020-01-23 06:52:00
问题 I have this bank ATM mock-up app which implements some Domain-Driven Design architecture and Unit of Work pattern. This app have 3 basic functions: Check balance Deposit Withdraw These are the project layers: ATM.Model (Domain model entity layer) namespace ATM.Model { public class BankAccount { public int Id { get; set; } public string AccountName { get; set; } public decimal Balance { get; set; } public decimal CheckBalance() { return Balance; } public void Deposit(int amount) { // Domain

Why the database data is not being updated but object did and without error?

风格不统一 提交于 2020-01-23 06:51:28
问题 I have this bank ATM mock-up app which implements some Domain-Driven Design architecture and Unit of Work pattern. This app have 3 basic functions: Check balance Deposit Withdraw These are the project layers: ATM.Model (Domain model entity layer) namespace ATM.Model { public class BankAccount { public int Id { get; set; } public string AccountName { get; set; } public decimal Balance { get; set; } public decimal CheckBalance() { return Balance; } public void Deposit(int amount) { // Domain

Eager Loading using UserManager with EF Core

人盡茶涼 提交于 2020-01-23 04:50:32
问题 Currently have ApplicationUser class with some custom properties, like: public class ApplicationUser : IdentityUser { public string Name { get; set; } public List<Content> Content { get; set; } } I'd like to get the current logged user with the list of related data ( Content property). In my controller, if I put: Applicationuser user = await _userManager.GetUserAsync(HttpContext.User); I get the logged user, but without any related data. But, if I retrieve the current user using the

Table per Type in Entity Framework Core 2.0

限于喜欢 提交于 2020-01-23 03:08:18
问题 These are my models: public class Company { public int CompanyId { get; set; } public string Name { get; set; } public string Address { get; set; } public string Email { get; set; } public string Url { get; set; } //... } public class HeadOffice : Company { public int HeadOfficeId { get; set; } public virtual List<BranchOffice> BranchOffice { get; set; } = new List<BranchOffice>(); } public class BranchOffice : Company { public int BranchOfficeId { get; set; } public virtual HeadOffice