Entity framework 调用实体框架函数从代码导入
因此,我在数据库中定义了一个名为Spr_EventLogCreate的存储过程。我已经在我的数据模型中创建了一个名为LogEvent的函数import,没有返回类型,我可以在 MyModel.edmx>MyModel>EntityContainer>Function Imports>LogEvent 我想我应该能够在我的代码中调用函数,如下所示:Entity framework 调用实体框架函数从代码导入,entity-framework,Entity Framework,因此,我在数据库中定义了一个名为Spr_EventLogCreate的存储过程。我已经在我的数据模型中创建了一个名为LogEvent的函数import,没有返回类型,我可以在 MyModel.edmx>MyModel>EntityContainer>Function Imports>LogEvent 我想我应该能够在我的代码中调用函数,如下所示: var context = new MyModelEntities(); context.LogEvent(...); 但是LogEvent()方法
var context = new MyModelEntities();
context.LogEvent(...);
但是LogEvent()方法不存在
我在这里一定很愚蠢,但是我该如何调用我的导入函数呢
使用VS 2008和EF 3.5.无法生成调用函数的代码,而不是在默认Microsoft designer中从设计时重新调整结果集。您可以编写代码,在上下文类的部分定义中手动调用它。 以下是一个例子:
public void EmpDelete (global::System.Nullable PEMPNO, global::System.Nullable PDEPTNO)
{
if (this.Connection.State != System.Data.ConnectionState.Open)
this.Connection.Open();
System.Data.EntityClient.EntityCommand command = new System.Data.EntityClient.EntityCommand();
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = @"DataSourceModel1Entities.EmpDelete";
command.Connection = (System.Data.EntityClient.EntityConnection)this.Connection;
EntityParameter PEMPNOParameter = new EntityParameter("PEMPNO", System.Data.DbType.Decimal);
if (PEMPNO.HasValue)
PEMPNOParameter.Value = PEMPNO;
command.Parameters.Add(PEMPNOParameter);
EntityParameter PDEPTNOParameter = new EntityParameter("PDEPTNO", System.Data.DbType.Decimal);
if (PDEPTNO.HasValue)
PDEPTNOParameter.Value = PDEPTNO;
command.Parameters.Add(PDEPTNOParameter);
command.ExecuteNonQuery();
}
在codegen文件中搜索
LogEvent
。你看到了吗?它应该在那里。是的,我也试过了,但根本没有对那个字符串的引用。我只是尝试删除并重新添加函数导入,然后再次搜索字符串“LogEvent”的整个解决方案,但我仍然看不到它。。。哦,你好,克雷格-你曾经在Interbase论坛上帮过我很多。嗯,谢谢。。。你知道为什么要这样实施吗?为什么不能自动生成调用代码?这是VS2008的问题。代码是在VS 2010 RC中生成的。@Devart我认为这是EF 1.0的问题。我使用VS2010和EF 1.0,但也有同样的问题。