entity-framework-5

How to make two way-databinding using EF in winforms?

我只是一个虾纸丫 提交于 2019-12-19 19:53:32
问题 I am very new at coding. Now I am going to tell you about my current situation and where I wanna go. Hope you will help. I am using EF5.0 database first approach and I want to be able to use gridviews for listing and updating the database values. Currently I am binding my data like this: pehlivan_kabametrajEntities ctx = new pehlivan_kabametrajEntities(); var result = from k in ctx.Kolons select k; dataGridView1.DataSource = result.ToList(); This code lists my data perfectly. However it is

how to get eager loading in a many to many relationships?

大城市里の小女人 提交于 2019-12-19 10:44:08
问题 I have a database with four tables. TableA and TableB are the main tables and the TableC is the table of the many to many relationships. TableA(IDTableA, Name...) TableB(IDTableB, Name...) TableC(IDTableA, IDTableB) This create three entities, The EntityA has an ICollection of Entity C and Entity C has a Collection of EntitiesB, so when I try to get the related entities I do this: myContext.EntityA.Include(a=>a.EntityB.Select(b=>b.EntityC)); But this throw and exception that says that the

Linq To Entities Compare Value Against List<int>

若如初见. 提交于 2019-12-19 10:22:39
问题 I am using Entity Framework 5.0 , and I have a problem with a LINQ query. I have the following method that accepts an integer value which is then passed into the query. This works fine. public IList<tblcoursebooking> GetStandardReport(int AttendanceID) { return _UoW.tblcoursebookingRepo.All .Where(cb => cb.Attended.Equals(AttendanceID) .ToList(); } However, I need to change the method so that it accepts a List of integers , and then pulls out all records where Attended is equal to any of the

Entity Framework - Database First without config

百般思念 提交于 2019-12-19 09:53:03
问题 I'm developing a class library that deals with an exiting db using EF. I want to avoid the consumer of the class library (and .exe or a web site) to have in the *.config file the Entity connection string. I want the connection string set a run-time. How do I set the connection string with Database First approach? There is no constructor overload that takes a connection string and when I created one (in a separate partial class) I got an "UnintentionalCodeFirstException". I have reviewed

Entity Framework - Database First without config

我是研究僧i 提交于 2019-12-19 09:52:08
问题 I'm developing a class library that deals with an exiting db using EF. I want to avoid the consumer of the class library (and .exe or a web site) to have in the *.config file the Entity connection string. I want the connection string set a run-time. How do I set the connection string with Database First approach? There is no constructor overload that takes a connection string and when I created one (in a separate partial class) I got an "UnintentionalCodeFirstException". I have reviewed

“The operation cannot be completed because the DbContext has been disposed” exception with lazy load disabled

允我心安 提交于 2019-12-19 09:49:23
问题 Given: public ActionResult List() { using (var unitOfWork = new UnitOfWork()) { var result = unitOfWork.Repository.Find<EntityAddress>(a => a.PostalCode == "80001"); //return View(result.ToList());//NO Exception raised with ToList() return View(result);//EXCEPTION RAISED IN VIEW DURING ITERATION } } UnitOfWork is disposable and handles disposal of my DbContext. It also disables lazy loading in the constructor: public UnitOfWork() { _dbContext.Configuration.LazyLoadingEnabled = false;

How to avoid System.Data.Entity.Infrastructure.DbUpdateException

瘦欲@ 提交于 2019-12-19 08:48:53
问题 I have this DbContext object which consists of - - Employee - CompanyAddress (PK: AddressFirstLine, City) Note: one Employee can have many CompanyAddress Records are added to CompanyAddress table only if some address doesn't exists in CompanyAddress table. If I have two DBContext objects from database say Snapshot1, Snapshot2. Say when both these snapshots were taken, there were no records in CompanyAddress table. When changes were made to Snapshot1 and saved - records are written to

Multiple databases(datacontext) on same server without MS DTC

守給你的承諾、 提交于 2019-12-19 03:06:07
问题 I'm using EF5.0 with SQL server 2008. I have two databases on the same server instance. I need to update tables on both databases and want them to be same transaction. So I used the TransactionScope. Below is the code - public void Save() { var MSObjectContext = ((IObjectContextAdapter)MSDataContext).ObjectContext; var AWObjectContext = ((IObjectContextAdapter)AwContext).ObjectContext; using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {

Are there technical reasons EF 5 isn't fully supported on .NET4.0?

北战南征 提交于 2019-12-18 20:49:29
问题 I wanted to upgrade my app to EF 5 to take advantage of features like support for enum spatial etc. However, I was not able to upgrade unless I move to .Net 4.5. I would like to know what features of .Net 4.5 does EF 5 use that it can not be done in .Net 4.0? 回答1: My understanding is that EF >= 4.1 (including EF 5) consists of the EF "core libraries" like ( System.Data.Entity.dll ) which are part of the .NET Framework the additional package/assembly you can download via Nuget which contains

Joining tables from two databases using entity framework

白昼怎懂夜的黑 提交于 2019-12-18 19:08:41
问题 I am working on an ASP.NET MVC 4 web application. I am using Entity Framework as the data access layer, using database first approach ( .edmx file). Currently I have a problem in join tables that are defined inside two different databases (i.e. I have two .edmx files). For example if I want to join tables I am performing the following query:- public ActionResult AutoComplete(string term) { var tech = repository.AllFindTechnolog(term).Take(100);//Call to the first database var resources =