objectcontext

Round trip logging in entity framework

I know this is possible in Linq-to-Sql, is it possible to automatically log all queries made through a particular ObjectContext in entity framework? In particular, I'm interested in the number of queries that are run in the lifetime of the ObjectContext. ...

MVC ASP.NET, ObjectContext and Ajax. Weird Behaviour

Hi, i've been creating a web application in mvc asp.net. I have three different project/solutions: One solution contains the model in EF (DAL) and all the methods to add, update, delete and query the objects in the model, the objectcontext is managed here in a per request basis. Other solution contains a content management system in w...

How to convert a DataSet object into an ObjectContext (Entity Framework) object on the fly?

Hi all, I have an existing SQL Server database, where I store data from large specific log files (often 100 MB and more), one per database. After some analysis, the database is deleted again. From the database, I have created both a Entity Framework Model and a DataSet Model via the Visual Studio designers. The DataSet is only for bulk...

EF4 - possible to mock ObjectContext for unit testing?

Can it be done without using TypeMock Islolator? I've found a few suggestions online such as passing in a metadata only connection string, however nothing I've come across besides TypeMock seems to truly allow for a mock ObjectContext that can be injected into services for unit testing. Do I plunk down the $$ for TypeMock, or are there a...

How Can i change Tracking Information of object from ObjectContext to another??

I have an object which is added to an objectContext .. after some operation i need to pass it to another objectcontext of the same database but i always face this message : An entity object cannot be referenced by multiple instances of IEntityChangeTracker. i need to change tracking information be detach it from the old object and...

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

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: //I...

Merge Function In Entity FrameWork?

when i use NHibernate i can find Merg function in session which do that : * if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance * if there is no persistent instance currently associated with the session, try to load it from the ...

ASP.Net Entity Framework, objectcontext error

I'm building a 4 layered ASP.Net web application. The layers are: Data Layer Entity Layer Business Layer UI Layer The entity layer has my data model classes and is built from my entity data model (edmx file) in the datalayer using T4 templates (POCO). The entity layer is referenced in all other layers. My data layer has a class call...

.Net Entity objectcontext thread error

I have an n-layered asp.net application which returns an object from my DAL to the BAL like so: public IEnumerable<SourceKey> Get(SourceKey sk) { var query = from SourceKey in _dataContext.SourceKeys select SourceKey; if (sk.sourceKey1 != null) { query = from SourceKey in query where ...

Why is ExecuteFunction method only available through base.ExecuteFunction in a child class of ObjectContext?

I'm trying to call ObjectContext.ExecuteFunction from my objectcontext object in the repository of my site. The repository is generic, so all I have is an ObjectContext object, rather than one that actually represents my specific one from the Entity Framework. Here's an example of code that was generated that uses the ExecuteFunction m...

Unable to use stored procs in a generic repository for the entity framework. (ASP.NET MVC 2)

Hi, I have a generic repository that uses the entity framework to manipulate the database. The original code is credited to Morshed Anwar's post on CodeProject. I've taken his code and modified is slightly to fit my needs. Unfortunately I'm unable to call an Imported Function because the function is only recognized for my specific ins...

Function Import and Repository pattern with Entity Framework 4.0

Could anyone advise me on how they've implemented the use of Function Imports when using the Repository pattern against EF 4.0? We have a table mapped to a Candidate Entity and also a Function Import off an existing sproc that maps to Candidate. This works great in EF but we're abstracting by use of Repositories which take on their con...

C# - Entity Framework add new object to ObjectContext

Hi, im working with Entity Framework, SQL and C#. i have a Table called Client and other called clients_phone. I have a form with a Xtragrid and using BindingSource I bind the IQueryable to the grid. myBindingSource = new BindingSource(); myBindingSource.DataSource = clients; //Clients it is the IQueryable<Client> myBindingSource.Dat...

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

Hi, 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 ...

ObjectContext.SaveChanges() violates primary key, throws UpdateException?

Paraphrasing from this MSDN documentation ... An INSERT statement is generated by the Entity Framework and executed on the data source when SaveChanges is called on the ObjectContext. If the INSERT operation succeeds, server-generated values are written back to the ObjectStateEntry. When AcceptChanges is called auto...

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

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 = injec...

Attach additional ObjectSets to ObjectContext from separate project

Hi, I hope this makes sense. I have a ASP.NET web application that uses Entity Framework. I have added a couple of custom tables to the db and created a separate project to handle the CRUD operations for those tables. I chose the separate project because I don't want future upgrades to the application to overwrite my custom features. ...

How to clear contents of ObjectContext in Entity Framework 1.0

Is there a method of manually clearing/resetting an ObjectContext back to its initial state? Note that I can't just instantiate a new context. This is using the 1.0 version of the Entity Framework. Thanks ...

EF4 DAL design and the ObjectContext: Argument with co-worker

Hello all. I work with a senior developer who is a guru .NET architect. We have had many constructive arguments over the last 6+ months and generally I concede defeat in most of our discussions. I have learned stacks from working with him. There is one design problem we are currently in disagreement with, however, and I would like some ...

How do I query navigation properites using linq to sql and ef

Hi, I am trying to strongly type a query for 3 ef objects using linq to sql. There are one-to-many relationships with product and category. My classes contain navigation properties and look like this. public partial class Product { public int ID {get;set;} public string Name {get;set;} public virtual ICollection<Group> NpGroup {get;se...