dbcontext

Repository Pattern with Entity Framework and MVC4 Building Dynamic Connection String

筅森魡賤 提交于 2019-12-11 08:23:20
问题 I am facing an issue while implementing the Repository Pattern [UoW] for MVC4 with EF6. Error: 'XX.DataAccess.Context' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TContext' in the generic type or method 'XX.DataAccess.WriteRepository' //Data Access layer Class for Saving/Deleting/Retriving etc. Inherits WriteRepository public class Common : WriteRepository<Context>, ICommon { //Method } //Repository Pattern public abstract class

Multiple dbcontexts with Repository, UnitOfWork and Ninject

那年仲夏 提交于 2019-12-11 07:45:16
问题 I am slowly getting to grips with EF, repository, UnitOfWork and Ninject and have included my implementation so far (see below). The purpose of my data layer is to provide the ability to read data from the existing HR system which has an Oracle back end, and provide addition functionality by consuming this data. The application I am building will use a SQL backend, currently I have just created some extra tables in the HR systems Oracle dbm but I want to keep this separate and hook in to

EF: select all entities of subclass (inheritance)

梦想与她 提交于 2019-12-11 07:16:36
问题 I am using the Database first approach and DbContext. I have several inheritance structures (TPH) in my data model. But DbContext only creates one DbSet for the base class, and none for the subclasses. How should I retrieve all Entities of a specified subclass? I cannot write queries based on the mapping criteria, as i had to remove those fields from the data model. Can I simply add a new DbSet to the Entities class (partial class) ? 回答1: You can add new properties returning DbSet s of your

Can I use Self Tracking Entities and DBContext in Entity Framework 4.1?

旧街凉风 提交于 2019-12-11 07:04:27
问题 I want to know if DBContext (EF 4.1) supports Self Tracking Entities. If yes, how can I do that? 回答1: No unless you rewrite the template to support them. The current template is dependent on ObjectContext API. 来源: https://stackoverflow.com/questions/6646281/can-i-use-self-tracking-entities-and-dbcontext-in-entity-framework-4-1

EntityFramework : The specified cast from a materialized 'System.String' type to the 'System.DateTime' type is not valid

蹲街弑〆低调 提交于 2019-12-11 06:59:52
问题 I have a SP which I am executing with help of SqlQuery method of DbContext.Database . I am calling it as follows: EDIT 1:- passing DateTime now var t = form["datetime"];//value is 2013-May-08 09:30 DateTime dtm; if (!DateTime.TryParse(t, out dtm))//successfully parses dtm = new DateTime(2013, 05, 8, 9, 30, 0); var rTime= new SqlParameter("@rTime", dtm); var result = UoW.ExecuteSp<SPResult>("spResult @rTime", rTime).ToList(); The last line throws the exception that specified cast from string

Data displaying null types

烂漫一生 提交于 2019-12-11 06:40:09
问题 I'm creating fantasy football game and I'm using Entity Framework for the mapping of my database. There is a table with all the possible football players called Players, a table that contains team information called Teams, a table that contains league information and a table keeps track of which player belongs to which team ( because one player can belong to many teams depending on which league they are in) called League Player. I'm running into a problem however, when I try to get all the

DbContext.SaveChanges() visibility within a TransactionScope

浪子不回头ぞ 提交于 2019-12-11 06:24:56
问题 Given a TransactionScope with 2 subsequently opened DbContexts, are changes saved by the first context guaranteed to be visible within the scope of second context? var txOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (var transaction = new TransactionScope(TransactionScopeOption.Required, txOptions)) { using (var context1 = new MyDbContext()) { context1.Employees.Single(e => e.Id == 1).Salary += 1; // Update context1.Employees.Remove(context1

Entity Framework DbContext dynamic instantiation with custom Connection String

天涯浪子 提交于 2019-12-11 06:07:26
问题 Migrating from ObjectContext to DbContext code-generation, I realized that context class generated (which inherits from DbContext) has no constructor that receives connectionString neither EntityConnection (like ObjectContext child class had). This is a problem in my application since I need to instantiate my context dynamically from the concrete Type, using a runtime generated connection string. 回答1: On your class that inherits the DbContext, you should be able to specify the base

EF 5 : OriginalValues are lost when context is disposed

情到浓时终转凉″ 提交于 2019-12-11 04:52:21
问题 I am novice in EF. So to test the optimistic concurrency I used EF 5,WPF and an already created database.The WPF project contains a MainWindow Having TextBox1 for searching customer via primary key, TextBox2 for customer's name edit,a textblock (txtLog) to log Field values and a save button. To simulate Concurrency access, in SQL Server 2008 Management Studio i excute the query " update client set r01_nomcli = 'GGGGG' where r01_codcli = '4112010002'; " before clicking on save Button. it works

DbContext requires manual load of navigation properties

两盒软妹~` 提交于 2019-12-11 04:19:47
问题 I recently upgraded my solution from EF5 to EF6.1.2, and changed my data access layer to use DbContext instead of ObjectContext. Some of my unit tests are failing, and I don't understand why. Example of old data access code: public virtual T Insert(T item) { if (item == null) { throw new ArgumentNullException("item", @"TaskDal.Insert"); } using (var ctx = ObjectContextManager<StoreDataContext>.GetManager("StoreDataContext")) { var task = new Task(); WriteNonKeyData(task, item); ctx