Questions tagged [objectcontext]

Core class within Entity Framework. Provides the methods to retrieve, query and manipulate entities within the entity model.

302 questions
0
votes
0 answers

When casting DBContext to an ObjectContext none of the entities are available

I have changed an existing project to use EF5 and code first. It is using a repository class which relies on the older ObjectContext. To keep the repository implementation the same I created a property on the DBContext which would return an…
Max
  • 1,543
  • 2
  • 16
  • 31
0
votes
2 answers

New object, but error: an object with the same key already exists in the objectstatemanager. the objectstatemanager cannot track multiple (...)

Student and Teacher are i relationship many-to-many. When I have Student existed in database, and want to add new Teacher, I try code below. But in line: addedTeachers.ForEach(a => dbStudent.Teacher.Add(a)); I get error "an object with the same key…
Saint
  • 5,397
  • 22
  • 63
  • 107
0
votes
1 answer

Is there any reason to use ObjectContext transaction handling with DbContext's SaveChanges?

I have a code like this: public abstract class DataContextBase { public DbContext DbContext { get; protected internal set; } public ObjectContext ObjectContext { get; protected internal set; } protected DbTransaction transaction; …
Zsolt
  • 3,263
  • 3
  • 33
  • 48
0
votes
2 answers

How can I use CompiledQuery

I used the linq to fetch the data from database before, but it looks like using CompiledQuery with Linq should be than using Linq by itself. I've try to use CompiledQuery, but it's throwing an exception. Following is my code: static readonly…
user1531714
  • 111
  • 13
0
votes
2 answers

'System.Data.Objects.ObjectContext' does not contain a constructor that takes 0 arguments

I have inherited some code (that happens a lot!) which looks a bit like this: (namespace omitted) public partial class SpatialDatabase : global::System.Data.Objects.ObjectContext { public string MY_PROCEDURE(Decimal arg1, Decimal arg2) { …
0
votes
1 answer

Attaching one object to another without context

I have two methods using the EF4 - one which returns a list of objects (Pages) within a using block, and another which creates a different type of object (Book). One of the properties on Book is FirstPage, which is an item from the first list of…
Echilon
  • 10,064
  • 33
  • 131
  • 217
0
votes
3 answers

Is it possible to auto update only selected properties on an existent entity object without touching the others

Say I have a bunch of boolean properties on my entity class public bool isActive etc. Values which will be manipulated by setting check boxes in a web application. I will ONLY be posting back the one changed name/value pair and the primary key at a…
0
votes
1 answer

Unexpected transaction commit, in nested entity context, entity framework 4.1

Here's my issue I have two forms, formA and formB, formB works as a dialog of formA within the scope of formA, defined with EntityContext contextA = new EntityContext(); somewhere in formA, it invokes new formB().ShowDialog(); After invoking…
0
votes
2 answers

sql query with entity framework

How can I use sql query, in sql language, if I used entity framework to make the connection? I understood from this post that ObjectContext.ExecuteStoreQuery won't help because it works only with some queries (not 1:1 to sql language). The other…
BornToCode
  • 9,495
  • 9
  • 66
  • 83
0
votes
1 answer

Entity framework, consuming context in webform app

Rather simple question regarding entity framework and how to consume the objectcontext. In a asp.net webform application I am implementing most of data getters in a data class and trying to determine if its better (in a generic sense of better) to…
Kiemo
  • 47
  • 1
  • 6
0
votes
1 answer

How to call ObjectContext.Refresh() when using ADO.NET Unit Testable Repository Generator

I'm using “ADO.NET Unit Testable Repository Generator" (described here) to generate the entity classes. This T4 template automatically generates the following classes, apart from the classes for the database objects: .cs - The…
escist
  • 763
  • 4
  • 13
  • 35
0
votes
1 answer

InvalidOperationException because of different ObjectContext objects

I'm facing an issue I don't really understand with Entity Manager (C#). I'm kinda new at this stuff so please bear with my noobness ^^ I'm trying to create an instance of UserQuestion (which makes the link in the DataBase between the tables…
BPruvost
  • 503
  • 2
  • 5
  • 16
0
votes
1 answer

Latest News, The ObjectContext instance has been disposed

I am trying to get the Latest News from my database but I keep getting this error: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. the error happens on the NewsEntity.GetObject()…
Michael
  • 421
  • 2
  • 10
  • 23
-1
votes
1 answer

How to find entity referred as a foreign key in Entity Framework dynamically

We have a Country class which is added as a reference in a few other entities: public class Country { public string Name { get; set; } } public class Group { public string Name { get; set; } public int CountryId { get; set; } …
Oxygen
  • 831
  • 4
  • 17
  • 42
-1
votes
1 answer

how do i switch my repositories so that i can use code First EF approch instead Model First Edmx Approch

In Existing project implementation done from edmx model first approach EF I have to use Code First approach . In existing project developed creating repository BO ,base Bo ,Enum classes . Have to reflect the same with just change in approach.
1 2 3
20
21