I have a snippet of LINQ code that I need to use in a lot of queries
let catchmentId = Convert.ToInt32(
phy.PhysicalProperty_binData.Substring(offset + 3, 1) +
phy.PhysicalProperty_binData.Substring(offset + 2, 1) +
phy.PhysicalProperty_binData.Substring(offset + 1, 1) +
phy.PhysicalProperty_binData.Substring(offset, 1))
This translates well to SQL (and is more than performant for my specific needs), but makes my queries look ugly. Is there any way I can make this less verbose? Perhaps an extension method that returns an Expression> ? Note that I don't want to fetch the data to the client side (run it on the server as SQL), which makes things a little more complicated. For example:
let catchmentId = phy.PhysicalProperty_binData.AnExtensionMethodHere<int>(offset)
I tried writing an extension method that does this, but the provider simply ignores that call or throws an exception stating it doesn't know how to translate that call to SQL. Can we somehow extend the SQL generator to do this for us or provide it something in a way that will generate the same SQL?
Thanks in advance!