dbcontext

How to specify the name of the table to be used by DbContext

喜夏-厌秋 提交于 2019-12-22 05:12:06
问题 This is a followback question from my earlier question. I was under the impression that if there're more than one table in the database, the name of the DbSet variable will be used to identify the table. However in the linked question it was clear that the DbContext was choosing Products table instead of Portfolio table even if the name of the variable was Portfolio . I can still change the variable name to anything and I am still getting data. So my question is how the tables are mapped by

what is the best practice to set up DbContext in StructureMap for console app?

送分小仙女□ 提交于 2019-12-22 01:40:21
问题 I use StructureMap, EF 4.1/POCO. Console app supposes to run 2 consequent operations upon some set of data, lets say operation1 and operation2. I set DbContext up as an singleton. This causes problem in operation2 as operation1 left some trash in its DbContext that prevent operation2 works well. In the same time I can not set up DbContext as 'per call' coz operation1 uses 2 repositories sharing the same DbContext passing through their constructor. So ideally I need reinitialize/reset/cleanup

MVC. Net Error: Format of the initialization string does not conform to specification starting at index 0

独自空忆成欢 提交于 2019-12-21 21:43:19
问题 My Connection String is: <add name="RpsEntities" connectionString="server=localhost;port=3306;database=db_rps_development;uid=root;password=" providerName="MySql.Data.MySqlClient" /> which is working fine in my DAL project where I have migrations configuration. My Above mentioned connection string is not working with .Net identity and that exists into MVcWebApp, let me show you how am I am using: My bootstrap class which I am calling from Global.asax public class Bootstrapper { public static

What DbContext project do I get to work with EF?

允我心安 提交于 2019-12-21 20:05:07
问题 I'm new to entity framework. I've got EF 4.2, from NuGet. Now I'm hearing it would be good to get DbContext. I've got into the extension manager and tried finding it, but I see about 8 there. Which is the "righ" one? I don't know if this matters but I use both C# and VB.NET. Also, I don't know if this matters or not, but I'm using a data-first model, not a code-first or model-first models, for doing EF development. 回答1: On your EDMX design surface, right-click and pick Add Code-Generation

What DbContext project do I get to work with EF?

白昼怎懂夜的黑 提交于 2019-12-21 20:01:37
问题 I'm new to entity framework. I've got EF 4.2, from NuGet. Now I'm hearing it would be good to get DbContext. I've got into the extension manager and tried finding it, but I see about 8 there. Which is the "righ" one? I don't know if this matters but I use both C# and VB.NET. Also, I don't know if this matters or not, but I'm using a data-first model, not a code-first or model-first models, for doing EF development. 回答1: On your EDMX design surface, right-click and pick Add Code-Generation

Top per group: Take(1) works but FirstOrDefault() doesn't?

霸气de小男生 提交于 2019-12-21 09:19:36
问题 I'm using EF 4.3.1 ... just upgraded to 4.4 (problem remains) with database-first POCO entities generated by the EF 4.x DbContext Generator . I have the following database named 'Wiki' (SQL script to create tables and data is here): When a wiki article is edited, instead of its record being updated, the new revision is inserted as a new record with the revision counter incremented. In my database there is one author, "John Doe", which has two articles, "Article A" and "Article B", where

How to update an existing Entity from ViewModel using Automapper and EF4 DbContext with Lazy Loading enabled

帅比萌擦擦* 提交于 2019-12-21 04:48:08
问题 I am using Automapper to map between Entity and ViewModel object (in both directions). The model uses EF4 DbContext POCOs and needs LazyLoading (and therefore Proxy Generation) enabled. I have come across a problem attempting to update an existing entity from a viewmodel. When I call Mapper.Map(vm, entity), Automapper throws an exception. My question is: how are you supposed to work with EF Proxy objects using Automapper? The code looks (simplified) like this: public class MyEntity { public

Entity Framework 6 - use my getHashCode()

感情迁移 提交于 2019-12-20 10:29:04
问题 There's a certain amount of background to get through for this one - please bear with me! We have a n-tier WPF application using EF - we load the data from the database via dbContext into POCO classes. The dbContext is destroyed and the user is then able to edit the data. We use "state painting" as suggested by Julie Lerman in her book "Programming Entity Framework: DBContext" so that when we add the root entity to a new dbContext for saving we can set whether each child entity is added,

Ninject, DbContext & Windows Service - New Instance Each Time Thread Runs?

空扰寡人 提交于 2019-12-20 06:16:52
问题 I'm current writing a Windows Service which connects to an existing service layer using Entity Framework (DbContext), and Ninject to inject the Respositories and DbContext instance. This is pretty much working with one caveat - I want a brand new DbContext instance each time the thread runs, whereas at the moment I'm getting the same one for the entire thread lifetime. My binding looks like this: Bind<IDbContext>().To<EnterpriseDbContext>().InThreadScope(); Bind<IUserRepository>().To

How to link one-to-one relationship when fk is different from pk - EntityFramework

假装没事ソ 提交于 2019-12-20 04:59:08
问题 I have a custom users table in my database and i want to create a one-to-one relationship with aspnetusers table so that when i register a new customer, applicationuser class through UserManager should add the username, email, password and school code to the users table and add an fk in its own table. IS there any tutorial/example implementing this kind of scenario? I am trying to add a one-to-one relationship with my users table but the fk is different than pk Users Table [columns] username