The answer to my question should be quite obvious, but I cannot find it. I have a edmx file that has one table. There is a field of type string
. EF always generates nvarchar for that (which is kind of expected), but I need an ntext
instead of nvarchar
for that field as 4000 is too small for me.
So tell me - what is the proper way to tell EF to generate ntext
fields?
PS Using Entity Framework 4, SQL CE 3.5
Just set the property "MaxLength" in the Designer to "Max". This will generate a ntext field in the SQL CE DB.
If your project contains an ADO.Net Entity Data Model (
.edmx
) then see Ladislav's excellent answer.But if you're using the Code First libraries and your project doesn't contain a
.edmx
then you can use theSystem.ComponentModel.DataAnnotations.ColumnAttribute
to specify the column type:I guess you are using model first, don't you? You can simply create custom T4 template for SQL DDL generation and include logic which will use
NTEXT
when field is defined with max size.Default template is on:
Just copy this template and find the logic where data type is created. Once you have your template change DDL Generation Template in model properties (in the designer) to your modified version.
There is much more you can do with generation template because you can add some annotations to your model (XML) and use them for custom logic in the SQL generation process.