>>>Hi Rob,
>>>
>>>May be you can also explain this strange code to me
>>>
>>>
>>>exec sp_executesql N'SELECT TOP (2)
>>> [Extent1].[op_code] AS [op_code],
>>> [Extent1].[first_name] AS [first_name],
>>> [Extent1].[last_name] AS [last_name],
>>> [Extent1].[password] AS [password],
>>> other columns
>>>
>>> FROM [dbo].[operator] AS [Extent1]
>>> WHERE [Extent1].[op_code] = @p0',N'@p0 varchar(8000)',@p0='333333'
>>>
>>>this is happening when I select an operator in the grid. I don't understand where the TOP(2) come from. I also would very much like to use the @p0 defined as char(6) instead of
>>>varchar(8000).
>>>
>>>The _dbSet.Find(id) method is being executed here.
>>
>>Find (and Single) will throw an error if there are two entries with the same key. The top 2 is to check for a duplicate entry. See the first exception at
http://msdn.microsoft.com/en-us/library/gg696418%28v=vs.113%29.aspx>
>Interesting. How did you deduce from this page and first exception that SELECT TOP(2) is implemented for this reason. I agree that sounds very plausible, but I wish there will be a bit more documentation about the actual implementation of this method in EF.
>
>>
>>The use of varchar(8000) is to allow caching of the query plan as far as I can tell. See
http://stackoverflow.com/questions/6538746/why-does-code-first-ef-use-nvarchar4000-for-strings-in-the-raw-sql-command>
>Thanks for that question link. Someone in that thread suggested to try using MaxLength (I was using StringLength), but it had no effect either for me. I'm using MetaDataType approach, e.g.
>
>
>public partial class OperatorMetadata
> {
> [Column(TypeName = "char")]
> [StringLength(6)]
> [MaxLength(6)]
> public String OpCode { get; set; }
>
>
> }
>
> [MetadataType(typeof(OperatorMetadata))] //http://ardalis.com/adding-attributes-to-generated-classes
> public partial class Operator
> {
> }
>
>Are you able to get it to work with one of these attributes or it's a current short-coming of the EF?
>
>Thanks again, Rob.
https://www.google.com/#q=entity+framework+top+2Is there a reason you care about what the type of the parameter is? Is the difference between a varchar(8000) and char(6) as a parameter type causing issues for you?