entity-framework-core

how to use multi DBContextPool?

独自空忆成欢 提交于 2019-12-31 01:51:29
问题 In EFCore 2.0 Add new feature, DbContext pooling. i know how to use it in single context, however, sometimes need multi context in project, public class BContext : DbContext { public BContext(DbContextOptions<BContext> options) : base(options) { } } public class AContext : DbContext { public AContext(DbContextOptions<AContext> options) : base(options) { } } ConfigureServices services.AddDbContextPool<AContext>(options => { options.UseInMemoryDatabase("AContext.InMemory"); }); services

How to call a stored procedure in EF Core 3.0 via FromSqlRaw

一世执手 提交于 2019-12-30 21:11:45
问题 I recently migrated from EF Core 2.2 to EF Core 3.0. Unfortunately, I haven't found a way to call a stored procedure that returns an entity. In EF Core 2.0 it was possible: var spParams = new object[] { "bla", "xx" }; var createdPath = ModelContext.Paths.FromSql("AddNodeWithPathProc @p0, @p1", spParams).Single(); In EF Core 3.0 the method FromSQL is replaced with FromSqlRaw . However, I didn't manage to successfully call a stored procedure and then process the value. This is useful when the

Multi-Context InMemory Database

点点圈 提交于 2019-12-30 18:53:13
问题 Is it possible to have an InMemory database (ASP.NET Core) that is shared across multiple DbContexts? It seems that each DbContext type keeps its own database, even when the same database name is specified in UseInMemoryDatabase. 回答1: The same name is enough. If your instances of DbContext do not 'see' the same in memory DB, it seems they use ones with different names. Make sure your DbContext is created once for the same name. EF Core 2.0 even re-uses in memory databases with the same name:

Ef-Core - What regex can I use to replace table names with nolock ones in Db Interceptor

别来无恙 提交于 2019-12-30 10:34:24
问题 I've been trying to port our EF6 project to EF-Core-2.0. In EF6, we were using DbNolock interceptor for adding With (NOLOCK) hint which queries we want. You can find my ex-running Db interceptor code below. public class DbNoLockInterceptor : DbCommandInterceptor { private static readonly Regex TableAliasRegex = new Regex(@"((?<!\){1,5})AS \[Extent\d+\](?! WITH \(NOLOCK\)))", RegexOptions.Multiline | RegexOptions.IgnoreCase); public override void ScalarExecuting(DbCommand command,

Where is the EDMX

橙三吉。 提交于 2019-12-30 08:08:49
问题 Getting exposed to dotnet Core. In a sample test application trying to setup EntityFramework.Core in dotnet core app. While I was able to add the EntityFramework.Core NugGet package I can't find the 'Add'->'New Item'->'Data'->'ADO.NET Entity Data Model' Is this not possible with EntityFramework.Core? How does EntityFramework.Core differ from EntityFramework 7? 回答1: There is no edmx support in Entity Framework Core. It only supports a code-first approach. The option to add a new Entity Data

Where is the EDMX

南楼画角 提交于 2019-12-30 08:08:06
问题 Getting exposed to dotnet Core. In a sample test application trying to setup EntityFramework.Core in dotnet core app. While I was able to add the EntityFramework.Core NugGet package I can't find the 'Add'->'New Item'->'Data'->'ADO.NET Entity Data Model' Is this not possible with EntityFramework.Core? How does EntityFramework.Core differ from EntityFramework 7? 回答1: There is no edmx support in Entity Framework Core. It only supports a code-first approach. The option to add a new Entity Data

The INSERT statement conflicted with the FOREIGN KEY constraint “FK_PostTag_Tag_TagId”

牧云@^-^@ 提交于 2019-12-30 07:46:41
问题 I am using Entity Framework 7 RC1 and I have the entities: public class Post { public Int32 Id { get; set; } public String Title { get; set; } public virtual IList<PostTag> PostsTags { get; set; } } public class Tag { public Int32 Id { get; set; } public String Name { get; set; } public virtual IList<PostTag> PostsTags { get; set; } } public class PostTag { public Int32 PostId { get; set; } public Int32 TagId { get; set; } public virtual Post Post { get; set; } public virtual Tag Tag { get;

Entity Framework Query using Contains with mulitple options

白昼怎懂夜的黑 提交于 2019-12-30 07:22:47
问题 Using entity framework to return a list of people where the forename contains text in a string array. Let's say: string[] search = new string[] { "bert", "rob" }; and query dataContext.People.Where(w => search.Any(a => w.Forename.Contains(a))); This compiles and works BUT the process is actually calling all records from the database and then performing my where clause on the returned data. This makes sense. Is there a way to rewrite the query so the where clause is generated in SQL? 回答1: I

Cannot access a disposed object Asp.net Identity Core

﹥>﹥吖頭↗ 提交于 2019-12-30 06:21:07
问题 I am getting this error System.ObjectDisposedException HResult=0x80131622 Message=Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take

Dealing with IReadOnlyCollection property in Entiry Framework Core 2.1

点点圈 提交于 2019-12-30 05:02:35
问题 I've got the following domain entity: public string Reference { get; private set; } public int SupplierId { get; private set; } public int BranchId { get; private set; } public Guid CreatedBy { get; private set; } public DateTime CreatedDate { get; private set; } public Source Source { get; private set; } public OrderStatus OrderStatus { get; private set; } public decimal NetTotal { get; private set; } public decimal GrossTotal { get; private set; } private List<PurchaseOrderLineItem>