How to use SUM in a string field by converting the value to int?

Asked

Viewed 71 times

1

I have a table that has a field PA that is string, it stores a 10 digit number and I can’t change the type of it because it references another table.

I’m trying to add this field like this:

Int32 somaBpaC = modelOff.bpacs.Sum(p => p.pa);

I get an expected error that cannot add the field pa that is string.

Is there any way to convert the field to int at the time of summation?

  • modelOff.bpacs is your Entity Framework and pa is a field that is a text, but that holds numbers?

1 answer

2


tried to make a value Parse:

Int32 somaBpaC = modelOff.bpacs.Sum(p => int.Parse(p.pa));
  • I’m getting the error: >System.Notsupportedexception: 'LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be Translated into a store Expression.'

  • is sure that a string that is returning to do this parse there in return?

  • I’m sure yes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.