Así que tengo un procedimiento almacenado llamado Spr_EventLogCreate definido en mi base de datos. He creado una función de importación en mi modelo de datos llamada LogEvent sin ningún tipo de retorno, y puedo ver esta función en el árbol del navegador de modelos en
MyModel.edmx> MyModel> EntityContainer> Importaciones de funciones> LogEvent.
Pensé que debería poder llamar a la función en mi código de la siguiente manera:
var context = new MyModelEntities();
context.LogEvent(...);
Pero el método LogEvent () no está presente.
Debo estar siendo realmente estúpido aquí, pero ¿cómo llamo a mi función importada?
Utilizando VS 2008 y EF 3.5.
No hay forma de generar el código que llama a la función sin volver a ajustar un conjunto de resultados del tiempo de diseño en el diseñador de Microsoft predeterminado. Puede escribir código llamándolo manualmente en la definición parcial de su clase de contexto. Aquí hay un ejemplo:
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();
}