Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map text field type of Sql server in EF code first? [duplicate]

I have a

1) text field type in my Sql server that I would like to map it to Entity framework 4.1 Code First. How can I do that?

2) When you declare a string variable in POCO classes, it maps to nvarchar in Sql Server. How it map it to varchar? I am pretty sure my data will always be English and not multilingual.

Thanks in advance :)

like image 941
Jaggu Avatar asked Feb 02 '26 15:02

Jaggu


1 Answers

Use this:

public class Foo
{
    [Column(TypeName = "ntext")]
    [MaxLength]
    public string TextProp {get; set;}
}

This should create ntext column in Sql Server and not nvarchar.

like image 142
TCM Avatar answered Feb 05 '26 05:02

TCM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!