dbcontext

Entity Framework DbContext Connection string in app.config/web.config not being seen

与世无争的帅哥 提交于 2019-12-11 03:56:12
问题 So, I have followed this instruction from ADO.NET team blog to try to make a small test project. I have double-checked everything. It doesn't seem to work and keeps saying connection string is missing. http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx Step. 1 Build this UserModels.dll. In the dll, App.Config file, edmx generated this connection string: (hit the 'test' button when making it, and it connects successfully, and generated the edmx

Recording changed values with DBContext Entry.OriginalValues and Entry.NewValues

孤者浪人 提交于 2019-12-11 02:23:38
问题 I have a document library site and would like to send an email when a document object is edited, containing a summary of the changes. The database interaction is Code First Entities Framework using DBContext Here is what I have so far: [HttpPost] public ActionResult Edit(Document document, bool sendEmail, string commentsTextBox) { if (ModelState.IsValid) { docsDB.Entry(document).State = EntityState.Modified; foreach (string propertyName in docsDB.Entry(document).OriginalValues.PropertyNames)

EF ObjectQuery<T> Context, Parameters, Connection properties equivalent on DbSet<T>

五迷三道 提交于 2019-12-11 02:09:54
问题 In the earlier versions of Entity Framework, we were able to reach the Context out of ObjectQuery in order to read Parameters , Connection , etc. as below: var query = (ObjectQuery<T>)source; cmd.Connection = (SqlConnection)((EntityConnection)query.Context.Connection).StoreConnection; cmd.Parameters.AddRange( query.Parameters.Select(x => new SqlParameter( x.Name, x.Value ?? DBNull.Value) ).ToArray() ); When I look at the DbSet<T> object, I am unable to find any equivalent of this. My purpose

Convert Library from ObjectContext to DbContext

て烟熏妆下的殇ゞ 提交于 2019-12-11 02:04:20
问题 I have a library (based on code found in an old blog post) that allows me to very easily wrap a façade around my data access using Entity Framework. It uses ObjectContext and has performed well enough for my purposes. But now, we are excitedly investigating code first using DbContext and of course would like to reuse / adapt as much of our existing effort as possible. Everything went ok naively converting our Facade enabling library with IObjectContextAdapter until we tried to utilise our

Is it possible to enable relationship fixup when change tracking is disabled but proxies are generated

纵饮孤独 提交于 2019-12-10 17:56:41
问题 I have entities which form a tree relationships. class MyEntity { public int Id {get;set;} public int ParentId {get;set;} public virtual MyEntity Parent {get;set;} public virtual ICollection<MyEntity> Children {get;set;} } When these entities are called without AsNoTracking() relationships are fixed up. var entities = MyEntitiesSet.ToList(); All navigation properties and collections are set. However if AsNoTracking() is called: var entities = MyEntitiesSet.AsNoTracking.ToList(); no navigation

NULL handling in dbcontext and objectcontext

Deadly 提交于 2019-12-10 13:08:08
问题 I have this simple LINQ query from e in Employees where e.DesignationID !=558 select e Here DesignationID is a nullable field: In objectcontext the query is translated to: SELECT [Extent1].[EmployeeID] AS [EmployeeID], [Extent1].[EmployeeCode] AS [EmployeeCode], [Extent1].[EmployeeName] AS [EmployeeName], [Extent1].[DesignationID] AS [DesignationID] FROM [dbo].[setupEmployees] AS [Extent1] WHERE 558 <> [Extent1].[DesignationID] While the same query in dbcontext it is translated to: SELECT

dbcontext loading related entities using select(), include() and where() not working

℡╲_俬逩灬. 提交于 2019-12-10 11:10:01
问题 I have the following relationship between the entities. Company 1 ---* Appointments *---1 Employee I have the .net asp membership in a separate database. Whenever a user is created it can be assigned to companies, employees, or administrators roles. in the Index action of my Company Controller, I check the logged in user's role. Based on the role, I make different linq query. For example, administrators can get list of all companies, companies can get list of company which has a username

Merge IdentityDbContext and DbContext ASP.NET MVC

本秂侑毒 提交于 2019-12-10 11:06:11
问题 I would like to only have one DbContext in my ASP.NET MVC project. How should I merge the default IdentityDbContext with my own code first DbContext? They are using the same database. public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("SignalRChat") { } } This is the default one provided in the IdentityModel.cs class. Is it safe to do the following? And append my own DbSets? public class ApplicationDbContext : IdentityDbContext

Adapter pattern for IDbSet properties of a DbContext class

放肆的年华 提交于 2019-12-10 10:50:08
问题 Is there a way to use the method described in this answer No FindAsync() method on IDbSet for DbSet properties of a DbContext? Edit: The answer linked contains a description how to build a interface inheriting from IDbSet and adding support for the SearchAsync method of the DbSet class. I understand everything which Keith Payne has written, but I don’t know how I can use it in DbContext. For example I’ve a DbContext which looks something like this: public class MyContext : DbContext { public

Microsoft.Data.Entity.Design, Version=10.0.0.0 is for Visual Studio Developer Preview 11

做~自己de王妃 提交于 2019-12-09 21:51:03
问题 I am trying something here but keep failing. I have Visual Studio Developer Preview installed on a Windows Server 2008 R2. As you know, for now VS extensions are not compatible with VS 11 Dev Preview but I found a workaround: Visual Studio Extensions and Visual Studio 11 Dev. Preview I installed ADO.NET C# DbContext Generator on VS 11 but when I try to run the code generation, I am getting the following error: Error: this template attempted to load component assembly 'Microsoft.Data.Entity