.Net Framework 4.5 AddObject()不会出现 [英] .Net Framework 4.5 AddObject() does not appear
问题描述
我有一个类,我想要插入
,更新
,删除
操作。
//构造函数。
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导入
;
不工作。
这是我要使用的方法: http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.addobject.aspx
UPDATE AGAIN:
我意识到我的DBEntities源于 DbContext $ .NET Framework 4.5中的c $ c>,但它来自.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 onContext
variable.AddObject()
method does not appear typing afterContext.
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;
orusing 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 fromObjectContext
in .Net Framework 3.5, so I was able to useAddObject()
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
toObjectContext
does it constitute any problem?解决方案Expand
YourModel.edmx
file. you can see 4 files there.Delete the files with.tt extension.
. Then double click onYourModel.edmx
file. InYourModel.edmx
diagram window right click and choseProperties.
In the properties window set Code Generation Strategy None to Default.
Cheers!!
这篇关于.Net Framework 4.5 AddObject()不会出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!