LINQ to Entities does not recognize the [Type] GetValue [Type] method

enter image description here I have a simple class like this:

Public Class CalculationParameter{
    public Long TariffId{get;set;}
}

      

In a workflow activity, I have an Assign like this:

(From tariffDetail In db.Context.TariffDetails
Where tariffDetial.TariffId = calculationParameter.TariffId).FirstOrDefault()

      

Dto is passed to Activity as input argument.

This throws the following error and I am wondering how to assign an ID. Any idea?

LINQ to Entities does not recognize the 'Int64 GetValue [Int64] (System.Activities.LocationReference)' method, and this method cannot be translated into a store expression.

How can I assign the calculation of the Parameter.TariffId to the tariffDetial.TariffId ?!

UPDATE: The attached screenshot shows that I am trying to assign calculationParameter.TariffId

to tariffDetail.TariffId

(car.Id = Dto.Id) and the query result should be assigned to an object CurrentTrafficDetail

.

+3


source to share


1 answer


Here is your problem. I don't know if he has a solution.

As you said in the comment (now removed, unfortunately needs me to answer) the exception you are getting is

LINQ to Entities does not recognize the Int64 GetValue [Int64] (System.Activities.LocationReference) method, and this method cannot be translated into a store expression.

in your Linq request, calculateParameter is a variable defined in the workflow. This variable is actually an instance that extends the System.Activities.LocationReference and NOT CalculationParameter types .

Typically, when a workflow is running, LocationReference stores all the information it needs to find the value that is assigned to it. This value is not restored until the last moment. At run time, the process of retrieving (getting the execution context, getting the value, converting it to the expected type) is controlled by the workflow.

However, when you introduce Linq into the mix, we have the problem you are facing. As you may or may not know, your expression will compile into the extension method version.

(From tariffDetail In db.Context.TariffDetails  
Where tariffDetial.TariffId = calculationParameter.TariffId)
.FirstOrDefault()

      

compiled into



db.Context.TariffDetails
          .Where(x => x.TariffId = calculationParameter.TariffId)
          .FirstOrDefault();

      

When this is done, L2E does not actually execute this code . It gets interpreted and converted into a SQL query that is executed against the database.

Since the interpreter is not omniscient, there is a well-defined set of restrictions on which methods you can use in an L2S request.

Unfortunately for you, getting the current value is LocationReference

not one of them.

TL: DR You can't do this.

As for workarounds, the only thing I think you can do is create a series of extension methods in your data context type, or add methods to your CalculationParameter class that you can call from the Expression editor.You can create your Linq to Entities queries in these methods, since all types will already be dereferenced by the workflow framework, which means you don't have to worry about the L2E interpreter choking on LocationReferences.

* Edit: A workaround can be found here (thanks to Slauma who mentioned this in the comment on the question)

+3


source







All Articles