开发者

EF4 Code First & SQLCE 4.0 - Exception when generating DB

开发者 https://www.devze.com 2023-03-31 15:52 出处:网络
I\'m using EF4 4.1 code first and attempting to use SQLCE as the data source. Everything works perfectly when pointing at a SQL Server 2008 instance, however when I change to SQLCE I get the followin

I'm using EF4 4.1 code first and attempting to use SQLCE as the data source.

Everything works perfectly when pointing at a SQL Server 2008 instance, however when I change to SQLCE I get the following exception:

String column with MaxLength greater than 4000 is not supported.

This is the property it's complaining about, as you can see it's length is set to 1024 character开发者_如何转开发s so I'm stumped as to why it's complaining about 4000?

[Required]
[DataType(DataType.Text), RegularExpression("http://www.*"), StringLength(1024)]
[Display(Name = "Page URL (http://www.)")]
public string Url { get; set; }

This is my connection string:

<add name="DataContext" connectionString="Data Source=|DataDirectory|db.sdf" providerName="System.Data.SqlServerCe.4.0" />

This is database initializer from global.asax:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataContext>());

Any ideas what I'm missing?

Thanks :)


Change the DataType to NVarchar (from Text)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号