0

I need to extract first numeric value set from a string. Here (Link Here), I have found a RegEx way to do that. But, in my case I have a LINQ query from where I need to do the same logic.

Here is my exisiting Logic

bool Isbn = db.BibContents.Any(ad => ad.NormValue == ISBN);  // I need to do the numeric split logic into the db column NormValue

Note

I cannot loop here to get values first and compare in the loop. Because, I have huge number of records in DB and NormValue Column is nvarchar(max) typed.

Any help to this will be appreciated.

Thanks

Community
  • 1
  • 1
DonMax
  • 970
  • 3
  • 12
  • 47

2 Answers2

0
bool Isbn = db.BibContents.Any(ad => GetDigits(ad.NormValue) == ISBN);

public string GetDigits(string text) {
     return string.Join("",text.AsEnumerable().Where(char.IsDigit));
}

How about that?

woutervs
  • 1,500
  • 12
  • 28
  • Getting this error `LINQ to Entities does not recognize the method 'System.String GetDigits(System.String)' method, and this method cannot be translated into a store expression.` – DonMax Mar 27 '14 at 09:37
  • Updated the method with string signature instead of int signature – woutervs Mar 27 '14 at 09:54
  • I used string signatured method only and got that above error. – DonMax Mar 27 '14 at 09:58
  • The problem is about the LINQ to Entities doest not work with user defined functions to convert it to store expression. – DonMax Mar 27 '14 at 10:00
  • In that case you have a few options, use linq to entities to create you own sql query, where you do the logic on the sql side. Or query all the data inside a list and then iterate over your list to retrieve the correct data. Since you say you have quite an extensive set of data the first option might be the better. (You could also create a stored procedure on your db.) http://msdn.microsoft.com/en-us/magazine/cc163473.aspx – woutervs Mar 27 '14 at 10:14
0

How about you parse your result to string? I don't know that much about LINQ but I would parse the result into String and use regex.

TuVi
  • 101
  • 1
  • 10