Redliru
Redliru

Reputation: 21

linq2db find string in varchar field

When I make a complex query and try to filter out the data on a varchar type column, the provider converting in sql code the required variable is not in the "where" block, and declares a variable of type NVarchar and assigns it a value. And block "where" adds search for that variable.

--  SqlServer.2008
DECLARE @cashRegisterNumber NVarChar -- String
SET     @cashRegisterNumber = N'0705311'

Because default nvarchar type has a length of 1, it looks for the first character. How to overcome and make it look the whole line?

Upvotes: 2

Views: 791

Answers (1)

IT.
IT.

Reputation: 878

Try Sql.AsSql method:

var str = "0705311";

...Where(t => t.Field1 == Sql.AsSql(str));

Upvotes: 2

Related Questions