.NET框架4.5 ADDOBJECT()不出现 [英] .Net Framework 4.5 AddObject() does not appear

查看:268
本文介绍了.NET框架4.5 ADDOBJECT()不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要插入更新删除类<在它/ code>操作。

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();

在这个班,我不能使用 ADDOBJECT()上下文变量c $ C>扩展方法。 ADDOBJECT()方法不会出现在上下文

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;



我能在.NET Framework 3.5的使用它,但不工作的.Net框架4.5

I was able to use it in .Net Framework 3.5 but not working on .Net Framework 4.5

我已经做错了

更新:

导入使用System.Data.Entity的>不工作

Importing using System.Data.Entity; or using System.Data.Objects; not working.

下面是我想使用的方法:的 http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.addobject.aspx

Here is the method I want to use: http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.addobject.aspx

再次更新:

我意识到我DBEntities派生从的DbContext :在.NET框架4.5,但它是从的ObjectContext 中派生.NET Framework 3.5的,所以我可以使用 ADDOBJECT()

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.

原始的实体类:

public partial class DBEntities : DbContext
    {
        // ...
    }

我想要做的是这样的:

public partial class DBEntities : ObjectContext
    {
        // ...
    }

如果我更改基类的DbContext >到的ObjectContext

If I change base class from DbContext to ObjectContext does it constitute any problem?

推荐答案

展开 YourModel.edmx 文件。你可以看到4个文件there.Delete与文件.TT扩展。。然后在 YourModel.edmx 双击文件。在 YourModel.edmx 图窗口点击右键并选择属性。

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.

屏幕截图

干杯!!

这篇关于.NET框架4.5 ADDOBJECT()不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆