Scorpion
Scorpion

Reputation: 4585

'System.Data.Services.Client.DataServiceContext.Execute<TElement>(System.Uri)' cannot be inferred from the usage

I am trying to update the statecode of a record in CRM 2011. But getting the following error while building the project.

Error

Error 1 The type arguments for method 'System.Data.Services.Client.DataServiceContext.Execute(System.Uri)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Code

var setStateReq = new SetStateRequest
{
    EntityMoniker = new EntityReference("new_entityname", 
            entityname.new_entitynameid),
            State = new OptionSetValue(1),
            Status = new OptionSetValue(2),
};
_context.Execute(setStateReq);

Thanks in advance

Upvotes: 0

Views: 661

Answers (2)

Scorpion
Scorpion

Reputation: 4585

I have done this using OrganizationServiceProxy rather than Context

using (var proxy = ProxyHelper.GetOrganizationServiceProxy())
{
    var setStateReq = new SetStateRequest
    {
        EntityMoniker = new EntityReference("new_entityname", 
        entityname.new_entitynameid),
        State = new OptionSetValue(1),
        Status = new OptionSetValue(2),
    };

    proxy.Execute(setStateReq);
}

Upvotes: 1

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

It means that the Execute<T> T generic argument method cannot be inferred as is.

You need to provide some type to the T generic parameter explicitly:

_context.Execute<SomeType>(setStateReq);

Upvotes: 1

Related Questions