How can the type of SQL query parameter be controlled when using a string property in .NET Entity Framework -
How can the type of SQL query parameter be controlled when using a string property in .NET Entity Framework -
on database table there column of type char(2).
when utilize parameter in linq such .where(x => x.code == code) sql query parameter translated varchar(max) char(2) in order avoid implicit conversion. because query not using indexes of database in way like.
property(c => c.code) .hascolumntype("char") .isfixedlength() .hasmaxlength(2); the code first mapping shown above. thing seems impact translation .hascolumntype("char") doesn't seem impact query translation, influences whether picks varchar(max) or nvarchar(max).
i have thought of 2 solutions, 1 database changed uses int , lookup instead of char code, other convert code utilize expression. 2 things i'd rather not do, if there improve way command mappings sql.
i worked out way accomplish this.
instead of using .where(x => x.code = code)
i using
var codes = new string[] { code } ...
.where(x => codes.contains(x.code)) this translates constant in query rather parameter.
entity-framework-4
Comments
Post a Comment