DarthVader DarthVader - 1 year ago 59
C# Question

Creating string index with Code first

I'm using Entity Framework 6.1 code-first and my domain model is below.

class Item
public string CreatedBy { set; get; }

When I use update-database for migration, I get the following error. However as far as I researched
should work as annotation to

Column 'CreatedBy' in table 'dbo.Items' is of a type that is invalid for use as a key column in an index.

Answer Source

Usually you get this error when you use a VARCHAR(Max) try using:

[Column(TypeName = "VARCHAR")]
public string CreatedBy { set; get; }

where n is between 1 and 450.