Search code examples
c#code-firstsql-server-ce-4

Large object (ntext and image) cannot be used in ORDER BY clauses


I wanted to change my code-first project to SQL Server Compact 4.0.

But I have a problem with following LINQ expression

db.Test.OrderBy(t => t.Name).ToList()

It throws the following error

Large object (ntext and image) cannot be used in ORDER BY clauses

Is there a way to tell code-first to create a nvarchar type for the Name field instead of the ntext type when creating the database?


Solution

  • Yes. Decorate the Name property of your entity class with this attribute:

    [Column(TypeName = "nvarchar(MAX)")]
    

    That should do the trick.