dbcontext

Invalid column name when trying to add an entity to a database using DbContext

痴心易碎 提交于 2020-01-17 05:53:11
问题 I'm trying to add an entity to my database with the following code: public void StoreElectronicSignatureType(ElectronicSignatureTypeModel model) { [...] ElectronicSignatureType electronicSignatureType = new ElectronicSignatureType(); Entity entity = GetEntity("Test"); electronicSignatureType.Entity = entity; Add(electronicSignatureType); public void Add(object entity) { DbContext.Entry(entity).State = System.Data.EntityState.Added; //DbContext.Set(entity.GetType()).Add (entity); DbContext

CRUD operations with connected POCOs instead of disconnected POCOs in EF code first

こ雲淡風輕ζ 提交于 2020-01-16 19:30:10
问题 I have an classic 3 layer project, that has these layers: UI (WinForm Project) BLL DAL(using EF codefirst) My entities are disconnected POCO s and I used them to pass data between layers and used them to bind to the UI controls. I load a graph of some related entities to UI(e.g. Order with it's OrderLine s and Product of each OrderLine ), user may add some new entities, edit some others and delete some others entities in this graph, and then send this graph to DAL to persist this changes to

should EF dbContext be created on every transaction

*爱你&永不变心* 提交于 2020-01-13 19:22:51
问题 I'm trying to figure out the best way to manage the DbContext. I've seen code samples that don't dispose and I've seen people say that that is a bad idea. Is it appropriate for me to do something like below? Also, should I put every transaction, including reads, in a new DbContext? This might be another question, but is the part about the EntityState necessary? public abstract class GenericRepository<T> where T : EntityData { protected MyDbContext Context { get { return new MyDbContext(); } }

How to use DbContext in T4 template?

五迷三道 提交于 2020-01-13 18:54:11
问题 I want to generate some code with a T4 Template using EntityFramework. I created a T4 Template in the same Assembly as my currently working EF6 DbContext: <#@ template language="C#" hostspecific="true" debug="True" #> <#@ assembly name="$(SolutionDir)\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #> <#@ assembly name="$(TargetPath)" #> <#@ import namespace="Conwell.Administration.Data.Entities" #> <# using (var db = new KassenautomatEntities()) { #> //Hello World <# } #> When

DBContext Find with Includes - where lambda with Primary keys

萝らか妹 提交于 2020-01-13 17:10:19
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

DBContext Find with Includes - where lambda with Primary keys

泪湿孤枕 提交于 2020-01-13 17:09:56
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

DBContext Find with Includes - where lambda with Primary keys

纵然是瞬间 提交于 2020-01-13 17:09:30
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

EF get list of records in runtime from Type

久未见 提交于 2020-01-13 10:36:12
问题 Purpose: I need to loop all records like: var records = db.Set<UserAccount>().ToList(); Then loop foreach (var record in records) { // do something with the record } But it has to not type specific in runtime, as I am to loop through types and therefor do not know example "UserAccount". Only the Type/TypeOf? In the bottom of this description I have a method loopAllEntities that I cannot find a way to work I have created an DbContext with some entities. public class MyEntities : DbContext {

Manage the lifetime of dbContext

a 夏天 提交于 2020-01-10 14:08:17
问题 I would like to tie the lifetime of a dbContext to the lifetime of a session, to - for example - be able to commit or abandon changes on a group of mutations on the dbcontext over multiple requests. Are there any other (better?) ways to accomplish this? If no, what would be a suitable mechanism to create and dispose of the contexts? I am thinking about static hashtables with cleanup on session end, but maybe I'm doing it All Wrong. I am also thinking about the idea of only holding on to those

Configure multiple database Entity Framework 6

删除回忆录丶 提交于 2020-01-09 04:38:49
问题 In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third project in my solution needs to use both databases. My problem is how to configure those context. I tried to create a configuration class in a separate assembly: namespace OSAD_Base { class EfDbConfiguration : DbConfiguration { public EfDbConfiguration() { SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices