3

So I have a stored procedure called Spr_EventLogCreate defined in my database. I have created a function import in my data model called LogEvent with no return type, and I can see this function in the Model Browser tree at

MyModel.edmx > MyModel > EntityContainer > Function Imports > LogEvent.

I thought I should then be able to call the function in my code as follows:

var context = new MyModelEntities();
context.LogEvent(...);

But the LogEvent() method is not present.

I must be being really stupid here, but how do I call my imported function?

Using VS 2008 and EF 3.5.

2
  • Search the codegen file for LogEvent. Do you see it? It should be there. Commented Mar 9, 2010 at 14:00
  • Yeah I tried that too, but there are no references to that string at all. I just tried deleting and re-adding the function import as well, and again searched the whole solution for the string "LogEvent", but I still can't see it... Oh, and hello Craig - you used to help me a lot on the Interbase forums. Commented Mar 11, 2010 at 2:49

1 Answer 1

2

There is no way to generate the code calling the function not retuning a result set from design time in default Microsoft designer. You can write code calling it manually in the partial definition of your context class. Here is an example:


        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();
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Hm thanks... any idea why it is implemented this way? Why can it not generate the calling code automatically?
It is a problem of VS 2008. The code is generated in VS 2010 RC.
@Devart I would say its a problem with EF 1.0. Im using VS2010 with EF 1.0 and having the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.