dbcontext

EXECUTE AS when using a DbContext with Linq

↘锁芯ラ 提交于 2019-12-08 09:49:34
I'm designing a multi-tenant database where each tenant is given a corresponding database user. The user is assigned access rights to the schema associated with the tenant and specific rights to objects in the dbo schema. Once I've identified the tenant, I want to switch to the appropriate user context by executing a SQL statement like the following: EXECUTE AS User = 'Tenant1' WITH NO REVERT When I execute this command using the ExecuteSqlCommand of the DbContext's Database property, everything seems to work correctly. When I later make changes to the model using Linq and call the method

EXECUTE AS when using a DbContext with Linq

无人久伴 提交于 2019-12-08 08:48:46
问题 I'm designing a multi-tenant database where each tenant is given a corresponding database user. The user is assigned access rights to the schema associated with the tenant and specific rights to objects in the dbo schema. Once I've identified the tenant, I want to switch to the appropriate user context by executing a SQL statement like the following: EXECUTE AS User = 'Tenant1' WITH NO REVERT When I execute this command using the ExecuteSqlCommand of the DbContext's Database property,

Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value?

淺唱寂寞╮ 提交于 2019-12-08 07:53:27
问题 I want to use the EF (4.2) in the following scenario: There exists a database already (so I chose the database-first approach) and it is a SQL Anywhere DB. I want to use persistence-ignorant business objects, so I use the DbContext Template to generate POCO classes from the EDM. There is one simple inheritance hierarchy among my entities: an abstract base entity and two concrete derived entities. In the database there is one table for each type of the inheritance hierarchy (Table-Per-Type

Managing connections with Generic Repository pattern

耗尽温柔 提交于 2019-12-08 04:37:58
问题 I am building a site using entity framework 4.1 and mvc3. I am using the Generic Repository pattern: http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle. I use ninject to inject my concretes repositories to the controllers. My problem is that each of my dbcontext different and I cannot run complex queries without the code shouting something like "different contexts cannot be used in the same query". I tried using the

Get DbContext for Entities

梦想与她 提交于 2019-12-08 04:34:19
问题 Okay, I feel a bit foolish for having to ask this but I guess my understanding of the inner workings of Entity Framework is lacking. I'd like to experiment with work with DbContext . I have an existing ASP.NET MVC application using EF 4.2. I can get my entities using: var context = new MyEntities(); And this works just fine. But how the heck to I get the same data represented by a DbContext ? 回答1: So I guess you are using default code generator provided by EDMX designer - it will use

This SqlTransaction has completed; it is no longer usable. Entity Framework Code First

笑着哭i 提交于 2019-12-08 04:28:19
问题 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.ComponentModel.DataAnnotations; using System.Data.Entity; namespace SqlEFTester { class Program { static void Main(string[] args) { ConnectionManager connectionManager = new ConnectionManager(); SqlConnection conn = connectionManager.Connection; conn.Open(); //BEGIN TRAN SqlTransaction tran = conn.BeginTransaction(); //Will do some legacy work using SqlTransaction,

How to fix 'A second operation started on this context before a previous operation completed…' when working with dependency injection?

别说谁变了你拦得住时间么 提交于 2019-12-08 02:38:14
问题 when reading data from the database I get this error: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe. I have the following ApplicationContext.cs: public class ApplicationContext : Microsoft.EntityFrameworkCore.DbContext { public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options) { } public DbSet<MyClass> MyClasses{ get; set; } } The following ApplicationContextFactory.cs

ASP.NET Boilerplate multiple databases and DbContexts

こ雲淡風輕ζ 提交于 2019-12-07 22:19:54
问题 I want to connect to two databases at once using ASP.NET Boilerplate. I followed this example: https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextEfCoreDemo The problem is that only the first context will have all the Abp tables on it. The second context is an existing database, which has none of the Abp tables on it. When I start up the web app, I get this: System.Data.SqlClient.SqlException: 'Invalid object name 'AbpLanguages'.' So obviously it is

Tomcat: javax.naming.NoInitialContextException

穿精又带淫゛_ 提交于 2019-12-07 17:25:17
问题 I have a webservice with Java Servlets on a Tomcat server. In my Servlet I use a database pool like this: envContext = new InitialContext(); DataSource ds = (DataSource) envContext.lookup( "java:/comp/env/jdbc/Database" ); con = ds.getConnection(); For initialisation I have this in my web.xml: <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/Database</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> Then there is

How do I pass a connection string to the constructor of a database-first DBContext with Entity Framework 4.1?

我怕爱的太早我们不能终老 提交于 2019-12-07 10:08:47
问题 For various reasons I would like to not store the connection string for my Entity Framework DB model in one of the various .config files. (I am using the latest and greatest DBContext API with the new Entity Framework version 4.1, .NET 4 and Visual Studio 2010 C#.) However, the code generation template for DBContext only creates a single parameterless constructor. (If I don't use the DBContext API, then my entity framework model has 7 different constructors to chose from, including the one I