objectcontext

IQueryable Repository with StructureMap (IoC) - How do i Implement IDisposable?

人走茶凉 提交于 2019-11-27 18:55:20
问题 If i have the following Repository: public IQueryable<User> Users() { var db = new SqlDataContext(); return db.Users; } I understand that the connection is opened only when the query is fired: public class ServiceLayer { public IRepository repo; public ServiceLayer(IRepository injectedRepo) { this.repo = injectedRepo; } public List<User> GetUsers() { return repo.Users().ToList(); // connection opened, query fired, connection closed. (or is it??) } } If this is the case, do i still need to

'ObjectContext' vs 'DbContext' in Entity Framework

ぃ、小莉子 提交于 2019-11-27 13:16:29
I'm using the DbContext class within code that I am creating that is based on the Generic Repositories and Unit of Work design patterns. (I am following the guidance here .) While working on this project I have encountered the ObjectContext class. I've read quite a number of posts that discuss ObjectContext vs. DbContext . While some of what I've read makes sense, I still don't have a complete understanding of the differences and this leaves me wondering about my current implementation. Should I be using DbContext , ObjectContext or both? Is using one of these now considered an anti-pattern?

Self Tracking Entities - AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager

做~自己de王妃 提交于 2019-11-27 13:10:50
问题 I've been stuck with this problem for over a week now. Hopefully some one can point me in the right direction. I start with a brief description of my schema. Asset 1--->1 Address *-->1 Area *-->1 Region *-->1 Country Package 1-->* Asset Using Self Tracking Entity (STE) + WCF. Steps: Call data store for a list of assets. Call data store for a list of packages. User selects a package and assign some assets to it. Save package. In step 2, the call uses eager loading of Addresses. from p in

Dynamic Translate to avoid C# syntax errors

倾然丶 夕夏残阳落幕 提交于 2019-11-27 07:09:01
问题 Consider the following database table (SQL Server 2005). I'd like to use this in EF (v6, .net 4.5.1) with the Translate function but after searching seems this is not supported. CREATE TABLE Foo ( pk INT NOT NULL PRIMARY KEY, Foo VARCHAR(100) ) Using by-convention mapping that would create a class Foo with a property Foo which is not supported by C# syntax. I tried using the ColumnAttribute : public partial class Foo { [Key] public virtual int pk {get;set;} [Column("Foo")] public virtual

Provider connection string from Entity Framework

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:42:27
问题 If you are using object contex data model (with EDMX file), during its creation you might want to specify the connection string inside your config file. The connection string is unfortunately not the common connection string as it contains some ...things needed for the entity connections. Example with MySql connection: <add name="MyDbEntities" connectionString="metadata=res://*/Namespace.MyDb.csdl|res://*/Namespace.MyDb.ssdl|res://*/Namespace.MyDb.msl;provider=MySql.Data.MySqlClient;provider

c# working with Entity Framework in a multi threaded server

醉酒当歌 提交于 2019-11-27 00:22:04
What is the best practice for working with entity framework in a multi threaded server? I'm using entity framework ObjectContext to manage all my database actions, now I know this context isn't thread safe, so for now when I need to use it to perform some db actions I surround it with lock statement to be safe. Is this how I should do it?? Some quick advices for Entity Framework in a multi-threaded environment: Don't use a unique context with locks (no singleton pattern) Provide stateless services (you need to instantiate and dispose one context per request ) Shorten the context lifetime as

c# working with Entity Framework in a multi threaded server

我与影子孤独终老i 提交于 2019-11-26 09:21:07
问题 What is the best practice for working with entity framework in a multi threaded server? I\'m using entity framework ObjectContext to manage all my database actions, now I know this context isn\'t thread safe, so for now when I need to use it to perform some db actions I surround it with lock statement to be safe. Is this how I should do it?? 回答1: Some quick advices for Entity Framework in a multi-threaded environment: Don't use a unique context with locks (no singleton pattern) Provide