dbcontext

Is there an EF6 DbContext Generator for C# which uses Fluent API?

落爺英雄遲暮 提交于 2019-12-09 07:12:53
问题 I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? 回答1: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a

Entity Framework Core 1.0 DbContext not scoped to http request

我只是一个虾纸丫 提交于 2019-12-09 06:44:35
问题 I understood by watching this video with Rowan Miller https://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/06 (at minute 22) that the way of configuring Entity Framework Core (previously known as EF7) into an ASP.NET Core 1.0 app (previously known as ASP.NET 5) in Startup.cs is as follows: public void ConfigureServices(IServiceCollection services) { //Entity Framework 7 scoped per request?? services.AddEntityFramework() .AddSqlServer() .AddDbContext<MyDbContext>(options => { options

Why is DbContext.SaveChanges 10x slower in debug mode

妖精的绣舞 提交于 2019-12-09 04:41:26
问题 Can somebody explain Why does DbContext.SaveChanges run ~10x slower in debug mode than production mode? Is there any way I can speed this up? In debug mode, my webpage takes 116 seconds to load versus 15 seconds if I start the project without debugging. I have set trace statements and identified that ~100 of the 116 seconds is spent in my DbContext.SaveChanges method when in debug mode. Running the project without debugging only 7 seconds in spent in the same section. Let me know in the

DbContext.Entry attaching Entity

为君一笑 提交于 2019-12-08 22:10:20
问题 From my research, I read that calling DbContext.Entry(someEntity) would automatically attached the entity to the context. However, when I do this I find that the entity's state is detached. Can anyone shed some light on this and how the DbContect.Entry works. I'm using EF 5.0 Thanks. 回答1: If you're wanting to attach an object, what you actually want is DbSet.Attach. DbContext.Entry is only giving you information about the entity, and allows you to change the state if it's already been

Migration: No DbContext was found in assembly

雨燕双飞 提交于 2019-12-08 20:38:21
问题 Using VS Community 2017. I have tried to create initial migration with error message saying: Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6. No DbContext was found in assembly 'Test_Project'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic. ... code in my dbcontext: protected override void OnModelCreating(DbModelBuilder mb) {

The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'

十年热恋 提交于 2019-12-08 19:31:45
问题 I am trying to return an entity object from entity framework 5.0.0 in a WCF service according to this tutorial by Rainer Stropek. I am using EF 5.x DbContext Generator with WCF Support. When I try to debug the service, I get this warning, which prevents it from running: The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'. F:\Dropbox\KelesoftSOMA\KelesoftSOMA.DataService.Administration\Web.config 40 6 KelesoftSOMA.DataService

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

馋奶兔 提交于 2019-12-08 19:18:35
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, so can not use TransactionScope here. MyContext context = new MyContext(conn); List<Inventory> list =

MVC4 Multiple Databases

荒凉一梦 提交于 2019-12-08 13:14:49
问题 I'm new to MVC4 framework & been working on an Licensing application that must use different databases for different products (each database contains handful tables for one product - all generated by proprietary licensing tool). My application shall be able to support CRUD functions on various products, thus requiring more than one DbContext objects in relation to different model for each product. As far as I know, each such DbContext object requires a connection string in the Web.config file

Updating DbSet<T> item's value from the controller - C#, MVC, Code First

倾然丶 夕夏残阳落幕 提交于 2019-12-08 12:14:26
here's my question: I have an MVC3 C# application and I need to update a value in a DbSet from the Edit controller, so the T item's value will be replaced with a new one. I don't want to delete the item and add it again. I cannot figure out how to do this. DbSet doesn't seem to have something like an index. Here's my Edit controller: public class ItemController : Controller { private SESOContext db = new SESOContext(); private FindQrs fqr = new FindQrs(); [HttpPost] public ActionResult Edit(Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; Qr qr = fqr.FindQr

How to use one database context for all instances that make use of a repository?

孤街醉人 提交于 2019-12-08 10:44:30
问题 I have made some architectural MVC-mistake since I did not know of the An entity object cannot be referenced by multiple instances of IEntityChangeTracker. error. My setup is as follows: I have a repository for accessing the database which creates an instance of dbcontext , I have controllers that instantiate managers they need, the managers all instantiate their own repository . Here is the problem, when a controllers uses more than one manager to collect data and then try to create an