entity-framework-core

Blazor concurrency problem using Entity Framework Core

妖精的绣舞 提交于 2020-05-11 11:02:19
问题 My goal I want to create a new IdentityUser and show all the users already created through the same Blazor page. This page has: a form through you will create an IdentityUser a third-party's grid component (DevExpress Blazor DxDataGrid) that shows all users using UserManager.Users property. This component accepts an IQueryable as a data source. Problem When I create a new user through the form (1) I will get the following concurrency error: InvalidOperationException: A second operation

How to handle concurrent DbContext access in dataloaders / GraphQL nested queries?

孤者浪人 提交于 2020-05-09 05:41:52
问题 I'm using a couple of dataloaders that use injected query services (which in turn have dependencies on a DbContext). It looks something like this: Field<ListGraphType<UserType>>( "Users", resolve: context => { var loader = accessor.Context.GetOrAddBatchLoader<Guid, IEnumerable<User>>( "MyUserLoader", userQueryService.MyUserFunc); return loader.LoadAsync(context.Source.UserId); }); Field<ListGraphType<GroupType>>( "Groups", resolve: context => { var loader = accessor.Context

How to select top N rows for each group in a Entity Framework GroupBy with EF 3.1

拟墨画扇 提交于 2020-05-09 05:37:08
问题 I need to get top 10 rows for each group in a table with entity framework. Based on other solution on SO, I tried 2 things: var sendDocuments = await context.Set<DbDocument> .Where(t => partnerIds.Contains(t.SenderId)) .GroupBy(t => t.SenderId) .Select(t => new { t.Key, Documents = t.OrderByDescending(t2 => t2.InsertedDateTime).Take(10) }) .ToArrayAsync(); error: System.InvalidOperationException: 'The LINQ expression '(GroupByShaperExpression: KeySelector: (d.SenderId), ElementSelector:

The property 'PropertyName' could not be mapped, because it is of type 'List<decimal>'

你说的曾经没有我的故事 提交于 2020-05-09 05:15:54
问题 I got this problem when I try to create the database with EntityFramework Core: The property 'Rating.RatingScores' could not be mapped, because it is of type 'List' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. Here is the class: public class Rating { public int Id { get; set; } public List<decimal> RatingScores { get; set; } public

The property 'PropertyName' could not be mapped, because it is of type 'List<decimal>'

陌路散爱 提交于 2020-05-09 05:15:13
问题 I got this problem when I try to create the database with EntityFramework Core: The property 'Rating.RatingScores' could not be mapped, because it is of type 'List' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. Here is the class: public class Rating { public int Id { get; set; } public List<decimal> RatingScores { get; set; } public

Entity Framework - [Keyless] Data Annotation Missing

好久不见. 提交于 2020-05-08 05:30:07
问题 According with the Microsoft Documentation Here, I should have access to the Attribute for [Keyless] so I can define my Model has Keyless, so that in my DBContext I could have something like: public DbSet<MyKeylessClass> KeylessModel { get; set; } And use _context.KeylessModel.FromSqlRaw(...) , without having the need to add a PK to it. I have the reference to System.ComponentModel.DataAnnotations and all the Attributes except Keyless are there, what am I missing here? 回答1: You've probably

Could not load file or assembly 'Microsoft.Data.SqlClient

╄→гoц情女王★ 提交于 2020-05-07 08:18:59
问题 I am calling a .net standard 2.0 library from a framework 4.7.2 test project sucessfully. If I take my .net standard 2.0 dll (SBD.Standard) and create a new winforms project that references it then I get asked to add Microsoft.EntityFrameworkCore, then Microsoft.EntityFrameworkCore.SqlServer, then Microsoft.Data.SqlClient and then my project runs successfully. (Although it would be ideal if the extra packages were added automatically) However trouble occurs if I try to distribute my library

Could not load file or assembly 'Microsoft.Data.SqlClient

孤街醉人 提交于 2020-05-07 08:17:53
问题 I am calling a .net standard 2.0 library from a framework 4.7.2 test project sucessfully. If I take my .net standard 2.0 dll (SBD.Standard) and create a new winforms project that references it then I get asked to add Microsoft.EntityFrameworkCore, then Microsoft.EntityFrameworkCore.SqlServer, then Microsoft.Data.SqlClient and then my project runs successfully. (Although it would be ideal if the extra packages were added automatically) However trouble occurs if I try to distribute my library

Could not load file or assembly 'Microsoft.Data.SqlClient

Deadly 提交于 2020-05-07 08:17:23
问题 I am calling a .net standard 2.0 library from a framework 4.7.2 test project sucessfully. If I take my .net standard 2.0 dll (SBD.Standard) and create a new winforms project that references it then I get asked to add Microsoft.EntityFrameworkCore, then Microsoft.EntityFrameworkCore.SqlServer, then Microsoft.Data.SqlClient and then my project runs successfully. (Although it would be ideal if the extra packages were added automatically) However trouble occurs if I try to distribute my library

User specific connection string in EntityFramework .net core

混江龙づ霸主 提交于 2020-04-18 05:45:56
问题 We are developing a multitenant app using .net core and EntityFramework. There will be a single deployed instance of APIs but multiple DBS( one DB per user). So what's the best strategy change DB connection string as per-user context. 回答1: Set the connection string in the OnConfiguring method of DbContext , by calling UseSqlServer , or whatever your database is. In this method, you need to have a reference to some service that will provide the user-specific connection. For this, IMO, the best