Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a long string in SQL database using Entity Framework

I'm trying to save the contents of a website to my database using Entity Framework. However, when the length of the HTML > 4000, I get these validation errors:

A first chance exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.DLL WebDev.WebServer40.exe Information: 0 : Property: RawData Error: The field RawData must be a string or array type with a maximum length of '4000'.

Any idea how to get around this? RawData is being created as NVARCHAR(4000) but a better type would be TEXT. Can I force that somehow?

Thanks!

like image 514
simon.d Avatar asked Dec 21 '22 07:12

simon.d


1 Answers

I'm using SQL CE 4.0 and having the very same problem. I managed to solve it using the following DataAnnotation (i like annotations :) )

public class Page
    {
        [Key]
        public int PageId { get; set; }

        [MaxLength]
        public string Content { get; set; }
    }

Now i can save whatever content in the Content property!

like image 60
Savvas Sopiadis Avatar answered Jan 23 '23 17:01

Savvas Sopiadis