Running the following query:
```
string value = "ABC1234567";
var data = from c in ctx.Posts
where c.PostId == value
select c;
```
Produces the following T-SQL:
```
exec sp_executesql N'SELECT
[Extent1].[PostId] AS [PostId],
[Extent1].[PostTitle] AS [PostTitle],
[Extent1].[Body] AS [Body],
[Extent1].[Author] AS [Author]
FROM [dbo].[Post] AS [Extent1]
WHERE [Extent1].[PostId] = @p__linq__0',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'ABC1234567'
```
Which causes a clustered index scan instead of a seek. However, if the SQL is changed to :
```
exec sp_executesql N'SELECT
[Extent1].[PostId] AS [PostId],
[Extent1].[PostTitle] AS [PostTitle],
[Extent1].[Body] AS [Body],
[Extent1].[Author] AS [Author]
FROM [dbo].[Post] AS [Extent1]
WHERE [Extent1].[PostId] = @p__linq__0',N'@p__linq__0 char(10)',@p__linq__0=N'ABC1234567'
```
This will result in a clustered index seek.
Here is the table and index structure:
```
CREATE TABLE [dbo].[Post](
[PostId] [char](10) NOT NULL,
[PostTitle] [varchar](100) NOT NULL,
[Body] [varchar](255) NOT NULL,
[Author] [char](50) NOT NULL
) ON [PRIMARY]
/****** Object: Index [ClusteredIndex-20141001-082832] Script Date: 10/1/2014 8:58:38 AM ******/
CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex-20141001-082832] ON [dbo].[Post]
(
[PostId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
```
A resolution to this would be greatly appreciated, we have a considerable amount of legacy data which uses char data types as primary keys.
Thanks!
Comments: How is PostId defined in your model, do you have MaxLength and IsUnicode= false defined?
```
string value = "ABC1234567";
var data = from c in ctx.Posts
where c.PostId == value
select c;
```
Produces the following T-SQL:
```
exec sp_executesql N'SELECT
[Extent1].[PostId] AS [PostId],
[Extent1].[PostTitle] AS [PostTitle],
[Extent1].[Body] AS [Body],
[Extent1].[Author] AS [Author]
FROM [dbo].[Post] AS [Extent1]
WHERE [Extent1].[PostId] = @p__linq__0',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'ABC1234567'
```
Which causes a clustered index scan instead of a seek. However, if the SQL is changed to :
```
exec sp_executesql N'SELECT
[Extent1].[PostId] AS [PostId],
[Extent1].[PostTitle] AS [PostTitle],
[Extent1].[Body] AS [Body],
[Extent1].[Author] AS [Author]
FROM [dbo].[Post] AS [Extent1]
WHERE [Extent1].[PostId] = @p__linq__0',N'@p__linq__0 char(10)',@p__linq__0=N'ABC1234567'
```
This will result in a clustered index seek.
Here is the table and index structure:
```
CREATE TABLE [dbo].[Post](
[PostId] [char](10) NOT NULL,
[PostTitle] [varchar](100) NOT NULL,
[Body] [varchar](255) NOT NULL,
[Author] [char](50) NOT NULL
) ON [PRIMARY]
/****** Object: Index [ClusteredIndex-20141001-082832] Script Date: 10/1/2014 8:58:38 AM ******/
CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex-20141001-082832] ON [dbo].[Post]
(
[PostId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
```
A resolution to this would be greatly appreciated, we have a considerable amount of legacy data which uses char data types as primary keys.
Thanks!
Comments: How is PostId defined in your model, do you have MaxLength and IsUnicode= false defined?