objectcontext

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

ObjectContext.Translate - Use different property names

时光怂恿深爱的人放手 提交于 2019-12-10 23:52:04
问题 I am using Entity Framework and calling a stored procedure as described here: http://msdn.microsoft.com/en-us/data/jj691402.aspx under "Accessing Multiple Result Sets with Code" After executing the stored procedure I am using the ObjectContext.Translate method to get my results into a data contract object, which requires that the data contract properties match up to the data returned. Is there any way I can use different property names, yet still have the Translate method map them correctly?

LogonUserEx, DuplicateTokenEx for Impersonation with an ObjectContext in C#

帅比萌擦擦* 提交于 2019-12-10 20:56:34
问题 We have a particular SQL Server which we need to access from a thick (.Net 4.0 WPF) client, and the only credentials available to us for that connection is a 'service' account which is effectively an Active Directory account with permission on the SQL Server. I am using Entity Framework, and ObjectContext, throughout the project, so am continuing with it here. After looking around, I have implemented an impersonation routine based on LogonUserEx, and DuplicateTokenEx, which allows me, via

How to get name of schema from entity framework?

拈花ヽ惹草 提交于 2019-12-10 17:56:09
问题 I have following code using (WdmEntities context = new WdmEntities()) { //get object models from context ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext; var container = objContext.MetadataWorkspace.GetEntityContainer(objContext.DefaultContainerName, DataSpace.CSpace); List<string> schemas = new List<string>(); foreach (var set in container.BaseEntitySets) { foreach (var metaproperty in set.MetadataProperties) { //here if(metaproperty.Name == "Schema") { //but

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

Compiled Query no implicit reference conversion to ObjectContext

廉价感情. 提交于 2019-12-08 18:36:36
问题 I'm creating a delegate to retrieve all album records in the database. I've used this same way in another project, but for some reason I'm getting an error this time. Have I missed a step? I'm not sure why this error is appearing. Code public static readonly Func<CodySolutionEntities, IQueryable<Album>> SelectAlbums = CompiledQuery.Compile<CodySolutionEntities, IQueryable<Album>>( query => from q in query.Albums.Include("Photo") select q); Error Error 1 The type 'CodyData.Diagram

Accessing HttpContext.Current in Data Access Layer

不羁岁月 提交于 2019-12-08 12:35:03
问题 Based on the given answer to my question at Entity Framework in layered architecture, Now I'd like to move my repositories (Which are now only responsible for CRUD abstraction, not business logic stuff) to DAL and reserve BLL for Business Logic. I've come to the conclusion that the entity context should be considered a unit-of-work and therefore not reused. So I'd like to create an obejctcontext per HttpContext in my repositories to prevent performance/thread [un]safety issues. I'd like to

Releasing ObjectContext while using StructureMap

ぃ、小莉子 提交于 2019-12-08 01:18:23
问题 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

Correct way to pass Entity objects between layers?

二次信任 提交于 2019-12-07 18:08:31
问题 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

Entity framework 6 data context from wcf data service

拈花ヽ惹草 提交于 2019-12-07 08:32:46
问题 I used to access the data context of my (ef 5.0) entities from inside a wcf data services service operation with this.CurrentDataSource.MyEntity . My data service inherited from DataService<T> . Now I wanted to use entity framework 6.0 and read on the internet, I should inherit the service from EntityFrameworkDataService<T> . But now from inside my service operations, I cannot access my data context anymore. this.CurrentDataSource doesn't contain any reference to the entities. 回答1: Here's my