dbcontext

Can I clone DbContext from existing one?

烂漫一生 提交于 2021-02-05 11:59:24
问题 I'm working on .NET Core Web API and I have one endpoint where I want to run three operations in parallel. All three of them use the same database, so I need three copies of DbContext. I created a simple Factory class, which I later inject into my "Data" class. Is it possible (if it's, is a good practice), to inject DbContext into my factory class (using built in .NET Core IoC) and when someone calls "CreateMyDbContext" method, just deep clone the one which was injected at the beginning? EDIT

Can I clone DbContext from existing one?

你离开我真会死。 提交于 2021-02-05 11:59:22
问题 I'm working on .NET Core Web API and I have one endpoint where I want to run three operations in parallel. All three of them use the same database, so I need three copies of DbContext. I created a simple Factory class, which I later inject into my "Data" class. Is it possible (if it's, is a good practice), to inject DbContext into my factory class (using built in .NET Core IoC) and when someone calls "CreateMyDbContext" method, just deep clone the one which was injected at the beginning? EDIT

How do I define multiple EF DbContexts that share the same structure so they can use methods interchangeably?

落花浮王杯 提交于 2021-01-29 16:00:11
问题 I am using a single database design for 3 different SQL Server locations (production, backup, master). The design is simple, shown below for the production location: Public Class ProductionDbContext Inherits DbContext Public Sub New() MyBase.New("ProductionDbConnection") End Sub Public Sub New(connectionString As String) MyBase.New(connectionString) End Sub Public Property Tables As DbSet(Of Table) 'Table includes a List(Of Topic) Public Property Topics As DbSet(Of Topic) 'for direct access

asp.net mvc multitenant database per tenant

末鹿安然 提交于 2021-01-29 10:05:15
问题 I'm building an app for our company which needs to have separate database per client. App is for the usage of other multiple companies, so the app needs to identify the company name when the user logs in and make the users operate only within their company db. I have it all set, but the problem is that the app is not able to handle 2 different databases simultaneously. When users from two different companies log in, the first users db gets changed to the db of the second user who is logged in

Setting WHERE condition to use Ids.Contains() in ExecuteSqlCommand()

前提是你 提交于 2021-01-27 20:18:57
问题 I'm using Entity Framework and I want to perform a bulk update. It is way too inefficient to load each row, update those rows, and then save them back to the database. So I'd prefer to use DbContext.Database.ExecuteSqlCommand() . But how can I use this method to update all those rows with an ID contained in my list of IDs? Here's what I have so far. IEnumerable<int> Ids; DbContext.Database.ExecuteSqlCommand("UPDATE Messages SET Viewed = 1 WHERE Id IN (@list)", Ids); I realize I could manually

Giving database context to object Factory

旧时模样 提交于 2021-01-27 13:21:50
问题 There is a question I always ask myself when I'm using a Factory pattern inside my code (C#, but it applies to any language I suppose). I have a "Service" that takes care of interacting with my database, do stuff with objects and interacts with my object model. This Service uses a Factory sometimes to delegate the instanciation of an object. But this factory obviously needs to interact by itself with the database to instanciate my object properly. Is it a good/bad practice to pass the