.Net Framework 4.5 AddObject()不会出现 [英] .Net Framework 4.5 AddObject() does not appear

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

问题描述

我有一个类,我想要插入更新删除操作。

  //构造函数。 
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 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: 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!!

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

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