varchar(max) means 2GB in SqlServer, not 8092, EF CodeFirst Gets it right

I wasted about 30 minutes wrestling with a EF CodeFirst type issue today.  I was creating an attribute for what I wanted to be a large text field and not have it limited to 8092 bytes which what I incorrectly thought required it to be something like varbinary, text or image types.  My CodeFirst code looks like this:

 

   1: [Column(TypeName = "Text")]   

   2: public string MimeMessageFull { get; set; }

 

What got created in my SqlServer database is the following:

   1: [MimeMessageFull] varchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

I kept changing things trying to make it text, image or varbinary with no success.  Finally, I ran into this url: 

http://msdn.microsoft.com/en-us/library/ms187993.aspx

which says clearly varchar(max) is the new image type.

image

So, there you have it.  ntext,text and image are out!

HTH’s.

About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP since 2007. In addition, he's a multi-course video author at Pluralsight. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


Follow

Get every new post delivered to your Inbox

Join other followers: