Entity Framework How to specify paramter type in generated SQL (SQLServer 2005) Nvarchar vs Varchar

Posted by Gratzy on Stack Overflow See other posts from Stack Overflow or by Gratzy
Published on 2010-06-03T19:47:13Z Indexed on 2010/06/03 21:14 UTC
Read the original article Hit count: 287

In entity framework I have an Entity 'Client' that was generated from a database. There is a property called 'Account' it is defined in the storage model as:

 <Property Name="Account" Type="char" Nullable="false"  MaxLength="6" /> 

And in the Conceptual Model as:

<Property Name="Account" Type="String" Nullable="false" />

When select statements are generated using a variable for Account i.e.

where m.Account == myAccount...

Entity Framework generates a paramaterized query with a paramater of type NVarchar(6). The problem is that the column in the table is data type of char(6). When this is executed there is a large performance hit because of the data type difference. Account is an index on the table and instead of using the index I believe an Index scan is done.

Anyone know how to force EF to not use Unicode for the paramater and use Varchar(6) instead?

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server-2005