ef-core-2.0

EntityFrameworkCore - How to inject IPrincipal when DbContextPool is enabled

只愿长相守 提交于 2021-01-28 04:41:32
问题 I have an aspnet core MVC application, and I need to inject the IPrincipal of the current request so that I know who is the current logged in user. I followed this article with no problem. Now I need the IPrincipal in my Dbcontext to auto-populate audit fields (CreatedBy, UpdatedBy, etc). Being naive I could inject the IPrincipal in my DbContext constructor: public MyDBContext(DbContextOptions<MyDBContext> options, IPrincipal principal) But I am using the DBContextPool , which reuses

How to group records and retrieve only first group with top N records

我只是一个虾纸丫 提交于 2021-01-27 08:23:11
问题 I have the following record set ID BatchID ClientName CreatedDateTime ----------- -------------- --------------- ----------------------- 1 NULL B 2018-02-16 19:07:46.320 2 NULL B 2018-02-16 19:07:46.320 3 NULL B 2018-02-16 19:07:46.597 4 NULL B 2018-02-16 19:07:46.597 5 NULL B 2018-02-16 19:10:10.260 6 NULL B 2018-02-16 19:10:10.260 7 NULL B 2018-02-16 19:21:34.303 8 NULL B 2018-02-16 19:21:34.303 9 NULL B 2018-02-16 19:21:44.780 10 NULL B 2018-02-16 19:21:44.780 11 NULL A 2018-02-16 19:24:35

How to group records and retrieve only first group with top N records

耗尽温柔 提交于 2021-01-27 08:20:37
问题 I have the following record set ID BatchID ClientName CreatedDateTime ----------- -------------- --------------- ----------------------- 1 NULL B 2018-02-16 19:07:46.320 2 NULL B 2018-02-16 19:07:46.320 3 NULL B 2018-02-16 19:07:46.597 4 NULL B 2018-02-16 19:07:46.597 5 NULL B 2018-02-16 19:10:10.260 6 NULL B 2018-02-16 19:10:10.260 7 NULL B 2018-02-16 19:21:34.303 8 NULL B 2018-02-16 19:21:34.303 9 NULL B 2018-02-16 19:21:44.780 10 NULL B 2018-02-16 19:21:44.780 11 NULL A 2018-02-16 19:24:35

Owned type property not persisting for a modified entity in EF Core

喜夏-厌秋 提交于 2021-01-22 10:28:37
问题 I'm trying to achieve something in EF Core that worked very well for me in EF 6. I'm serializing the contents of a List<T> property as a Json string in the DB. <T> can be pretty much anything, since Json.Net takes care of serializing whatever we throw at it. My collection exposes a Json string property and takes care of serializing/deserializing itself. This approach is convenient and efficient for structured nested data where a relational model would bring needless overhead and complexity.

Owned type property not persisting for a modified entity in EF Core

你说的曾经没有我的故事 提交于 2021-01-22 10:28:34
问题 I'm trying to achieve something in EF Core that worked very well for me in EF 6. I'm serializing the contents of a List<T> property as a Json string in the DB. <T> can be pretty much anything, since Json.Net takes care of serializing whatever we throw at it. My collection exposes a Json string property and takes care of serializing/deserializing itself. This approach is convenient and efficient for structured nested data where a relational model would bring needless overhead and complexity.

.Net Core 2 EF core connection string problem

回眸只為那壹抹淺笑 提交于 2020-12-13 03:41:28
问题 this is my appsettings.json "ConnectionStrings": { "Circolari": "Server=abcde;Database=Circolari;Trusted_Connection=True;" } and this is my startup.cs public Startup(IConfiguration configuration, IHostingEnvironment env) { Configuration = configuration; IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = configurationBuilder.Build(); } // This method

.Net Core 2 EF core connection string problem

ε祈祈猫儿з 提交于 2020-12-13 03:40:34
问题 this is my appsettings.json "ConnectionStrings": { "Circolari": "Server=abcde;Database=Circolari;Trusted_Connection=True;" } and this is my startup.cs public Startup(IConfiguration configuration, IHostingEnvironment env) { Configuration = configuration; IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = configurationBuilder.Build(); } // This method

How to stop EF Core from indexing all foreign keys

谁说我不能喝 提交于 2020-12-08 06:58:22
问题 As documented in questions like Entity Framework Indexing ALL foreign key columns, EF Core seems to automatically generate an index for every foreign key. This is a sound default for me (let's not get into an opinion war here...), but there are cases where it is just a waste of space and slowing down inserts and updates. How do I prevent it on a case-by-case basis? I don't want to wholly turn it off, as it does more good than harm; I don't want to have to manually configure it for all those