我有一个类,我想要插入,更新,删除操作。
//构造函数。 public BaseManager() { //禁用延迟加载。 this.Context.Configuration.LazyLoadingEnabled = false; } public DBEntities Context = new DBEntities();在这个类中,我不能使用 AddObject()扩展方法在上下文变量。 AddObject()方法在上下文后不会显示。
这是我的导入的命名空间:
using System; 使用System.Collections.Generic; 使用System.Data.Linq; 使用System.Text;我可以在.Net Framework 3.5中使用它,但不能使用.Net Framework 4.5
更新:
使用System.Data.Entity; 或使用System.Data.Objects导入; 不工作。
这是我要使用的方法: msdn.microsoft/en-us/library/system.data.objects.objectcontext.addobject.aspx
UPDATE AGAIN:
我意识到我的DBEntities源于 DbContext ,但它来自.Net Framework 3.5中的 ObjectContext ,所以我可以使用 AddObject()方法。
原始实体类:
public partial class DBEntities:DbContext { // ... }我想这样做:
public partial class DBEntities:ObjectContext { // ... } pre>如果我将基类从 DbContext 更改为 ObjectContext 是否构成任何问题?
解决方案展开 YourModel.edmx 。您可以在其中看到4个文件。使用 .tt扩展名删除文件。。然后双击 YourModel.edmx 文件。在 YourModel.edmx 图窗口右键单击并选择属性。
在属性窗口中,将代码生成策略无设置为默认。
干杯!!
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: msdn.microsoft/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!!
更多推荐
.Net Framework 4.5 AddObject()不会出现
发布评论