Linq equivalent of SQL LEFT function?

前端 未结 3 1593
离开以前
离开以前 2021-01-19 10:48

We have a database with some fields that are varchar(max) which could contain lots of text however I have a situation where I only want to select the first for example 300 c

3条回答
  •  青春惊慌失措
    2021-01-19 11:16

    You can use functions that directly translate to those functions too, this is useful when you need to translate code that functionally works just fine in SQL at no risk in LINQ. Have a look at System.Data.Objects.EntityFunctions

    Locations.Select(loc=>System.Data.Objects.EntityFunctions.Left(loc.Field,300))
    

    This will get directly translated into a LEFT on the server side.

提交回复
热议问题