I have a class that I want to make Insert
, Update
, Delete
operations in it.
// Constructor.
public BaseManager()
{
// Disable lazy loading.
this.Context.Configuration.LazyLoadingEnabled = false;
}
public DBEntities Context = new DBEntities();
In this class, I can't use AddObject()
extension method on Context
variable. AddObject()
method does not appear typing after Context.
Here are my imported namespaces:
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Text;
I was able to use it in .Net Framework 3.5 but not working on .Net Framework 4.5
What I've doing wrong?
UPDATE:
Importing using System.Data.Entity;
or using System.Data.Objects;
not working.
Here is the method I want to use: http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.addobject.aspx
UPDATE AGAIN:
I realized that my DBEntities derives from DbContext
in .Net Framework 4.5 but it was deriving from ObjectContext
in .Net Framework 3.5, so I was able to use AddObject()
method.
Original entities class:
public partial class DBEntities : DbContext
{
// ...
}
I want to do like this:
public partial class DBEntities : ObjectContext
{
// ...
}
If I change base class from DbContext
to ObjectContext
does it constitute any problem?
Expand YourModel.edmx
file. you can see 4 files there.Delete the files with .tt extension.
. Then double click on YourModel.edmx
file. In YourModel.edmx
diagram window right click and chose Properties.
In the properties window set Code Generation Strategy None to Default.
Cheers!!
AddObject
exists on each entity inside your container.
Context.TableName.AddObject(New TableElement...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With