objectcontext

Entity Framework - Where is my Object Context?

余生颓废 提交于 2019-12-06 17:17:33
问题 Ok, I'm obviously missing something very basic. I'm very new to Entity Framework. I want to call stored procedures without importing them, so I was planning on using ExecuteStoreQuery(). According to the documentation, ExecuteStoreQuery is a method of ObjectContext. But, I have no idea where to get my ObjectContext. I generated my entites using Database First. So far, I have been accessing my entities something like this: var db = new MyEntities(); PRODUCT p = db.PRODUCTS.First(a => a

Releasing ObjectContext while using StructureMap

蓝咒 提交于 2019-12-06 12:10:21
I've been using StructureMap to inject ObjectContext (entities) into my repositories along with lazy-loaded POCO classes. This is my Structuremap registration. For<WebEntities>().LifecycleIs(new HybridLifecycle()).Use(()=>new WebEntities()); I have defined Partial classes against my POCO classes to retrieve info that is not defined in my EDMX schema. e.g. Community.FloorPlanImages would be a getter which filters only the floor plan images from all available Images. Worked pretty well until I started to optimize my queries. Using EFProf, I found out that none of my connections were being closed

Add EF 6.x EntityObject Generator in Visual Studio 2017

核能气质少年 提交于 2019-12-06 10:49:08
We are planning to switch to Visual Studio 2017. For our Entity Framework 6 edmx file we use the EntityObject Generator extension to create us the desired ObjectContext. This extension is only compatible up to VS2013 - inofficially up to VS2015. The solution to simply adjust the manifest file in the vsix does not seem to work for VS2017 though - I guess among others because the vsix architecture changed. Is there a way to get the ObjectContext template without using an old Visual Studio? I assume the template is not always the same for each edmx file so it could simply be copy pasted from an

Defining data annotation using DbContext versus Objectcontext in the database first approach

我是研究僧i 提交于 2019-12-06 07:16:32
问题 I am using the database first approach with entity framework, when i used to work on the default template the database tables were mapped using the ObjectContext, so i used to create #partial classes & [MetadataType(typeof ) to apply the data annotation ,, but when i start using the Dbcontext code generation template to map the database tables i found that it will create .tt folder in my Model area were i find that i can apply the data annotation directly to the .cs classes themselves without

Entity Framework and Object Context lifetime in ASP.NET MVC

本秂侑毒 提交于 2019-12-06 05:14:57
问题 I'm using Entity Framework in my project, and I have the problem that, once I pass my entities to a View (keep in mind that these entities have lazy-initialized objects along the lines of: Products.Owner, where owner is an object that is lazily initialized) I get a run-time exception telling me that the ObjectContext is out of scope. Now this makes sense since I am getting the entities from a Service with a using (.... entities...) { .... } statement, which means it is disposed when the

Correct way to pass Entity objects between layers?

断了今生、忘了曾经 提交于 2019-12-05 20:56:23
I am just learning the Entity Framework and have made some good progress on incorporating it with my layered code structure. I have 2 visual layers, a business layer and a data access layer. My problem is in passing entity object between layers. This code sample does not work: // BLL public static void Test1() { List<User> users = (from u in GetActiveUsers() where u.ID == 1 select u).ToList<User>(); // Do something with users } // DAL public static IQueryable<User> GetActiveUsers() { using (var context = new CSEntities()) { return from u in context.Users where u.Employee.FirstName == "Tom"

3 methods for adding a “Product” through Entity Framework. What's the difference?

情到浓时终转凉″ 提交于 2019-12-05 20:25:43
问题 Reading this MSDN article titled "Working with ObjectSet (Entity Framework)" It shows two examples on how to add a Product.. one for 3.5 and another for 4.0. http://msdn.microsoft.com/en-us/library/ee473442.aspx Through my lack of knowledge I am possibly completely missing something here, but i never added a Product like this: //In .NET Framework 3.5 SP1, use the following code: (ObjectQuery) using (AdventureWorksEntities context = new AdventureWorksEntities()) { // Add the new object to the

Entity Framework - Where is my Object Context?

旧时模样 提交于 2019-12-04 22:54:36
Ok, I'm obviously missing something very basic. I'm very new to Entity Framework. I want to call stored procedures without importing them, so I was planning on using ExecuteStoreQuery(). According to the documentation, ExecuteStoreQuery is a method of ObjectContext. But, I have no idea where to get my ObjectContext. I generated my entites using Database First. So far, I have been accessing my entities something like this: var db = new MyEntities(); PRODUCT p = db.PRODUCTS.First(a => a.PRODUCTSKEY == thekey); But I can't call db.ExecuteStoreQuery, becase db isn't an ObjectContext. I've googled

Entity Framework - refresh objects from database

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:13:20
问题 I'm having trouble with refreshing objects in my database. I have an two PC's and two applications. On the first PC, there's an application which communicates with my database and adds some data to Measurements table. On my other PC, there's an application which retrives the latest Measurement under a timer, so it should retrive measurements added by the application on my first PC too. The problem is it doesn't. On my application start, it caches all the data from database and never get new

Defining data annotation using DbContext versus Objectcontext in the database first approach

时间秒杀一切 提交于 2019-12-04 14:54:59
I am using the database first approach with entity framework, when i used to work on the default template the database tables were mapped using the ObjectContext, so i used to create #partial classes & [MetadataType(typeof ) to apply the data annotation ,, but when i start using the Dbcontext code generation template to map the database tables i found that it will create .tt folder in my Model area were i find that i can apply the data annotation directly to the .cs classes themselves without the need to create partial classes as in objectcontext case . Currently the data annotations are