Case insensitive string compare with linq-to-sql and linq-to-objects

前端 未结 3 1966
野性不改
野性不改 2021-01-17 21:18

see also Differences between LINQ to Objects and LINQ to SQL queries

We are using the some queries over our database and our

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 21:53

    Case sensitivity in your SQL database is determined by the collation setting. By default, I think most databases are case insensitive, so you should check whether you actually need to handle case sensitivity explicitly.

    In a collation setting of SQL_Latin1_General_CP1_CI_AS - CI stands for case insensitive and AS stands for accent sensitive.

    Unfortunately, Linq-to-Sql ignores the extra parameters of String.Compare() so you won't be able to explicitly set the case sensitivity to compare with. It will work with linq to objects however.

    If you use a case sensitive collation, you could use something like SqlMethods.Like(field, "string") to use a LIKE query - which is case insensitive -, but that doesn't translate into linq to objects.

提交回复
热议问题