-3

So here is my call

Guid deliveryId = p.DeliveryDomainId;
string test = "TEST";
Guid realDeliveryID = Changepoint_Entities.P_BOOST_GENGetCodeDetailId(test, deliveryId);

And this is the method I try to call wich is an SQL procedure, the code is auto generated from a dmx file so I can't change this :

public virtual ObjectResult<Nullable<System.Guid>>P_BOOST_GENGetCodeDetailId(string codeType, Nullable<System.Guid> codeDetail)
{
    var codeTypeParameter = codeType != null ?
        new ObjectParameter("CodeType", codeType) :
        new ObjectParameter("CodeType", typeof(string));

    var codeDetailParameter = codeDetail.HasValue ?
        new ObjectParameter("CodeDetail", codeDetail) :
        new ObjectParameter("CodeDetail", typeof(System.Guid));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<System.Guid>>("P_BOOST_GENGetCodeDetailId", codeTypeParameter, codeDetailParameter);
}

I get this error when compiling :

Error 30 An object reference is required for the non-static field, method, or property 'EBE.Entities.Changepoint_Entities.P_BOOST_GENGetCodeDetailId(string, System.Guid?)' d:\userfiles\aorset\documents\gitrepo\dpaebe\ebe_final\ebe_final\controllers\datacontroller.cs 462 39 EBE_Final

I am a bit of a noobie in C# so I don't really what I am doing wrong. Do I need to use statics or something ? Because the call is in a for loop so I don't know what to do. Thanks in advance :)

maccettura
  • 10,514
  • 3
  • 28
  • 35
Darkpingouin
  • 196
  • 12

2 Answers2

1

As the error message states, you need an instance of Changepoint_Entities:

Guid deliveryId = p.DeliveryDomainId;
string test = "TEST";
Changepoint_Entities changepoint = new Changepoint_Entities();
Guid realDeliveryID = changepoint.P_BOOST_GENGetCodeDetailId(test, deliveryId);
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
1

P_BOOST_GENGetCodeDetailId() is a non-static method but you ae calling like a static method and thus the error. You need to create a instance of Changepoint_Entities and call the method on that instance

Guid realDeliveryID = new Changepoint_Entities().P_BOOST_GENGetCodeDetailId(test, deliveryId);

(or) define the method as static

public static ObjectResult<Nullable<System.Guid>>P_BOOST_GENGetCodeDetailId(string codeType, Nullable<System.Guid> codeDetail)
{
Rahul
  • 76,197
  • 13
  • 71
  • 125