开发者

(0x80004005): Column length too big for column 'ModelHash'

开发者 https://www.devze.com 2023-03-24 09:17 出处:网络
I am using code first in EF 4.1 Update 1 with MySQL and the 6.4.3 .NET connector. I get the following exception:

I am using code first in EF 4.1 Update 1 with MySQL and the 6.4.3 .NET connector. I get the following exception:

MySql.Data.MySqlClient.MySqlException (0x80004005): Column length too big for 开发者_如何学Pythoncolumn 'ModelHash' (max = 21845); use BLOB or TEXT instead

How do I tell EF to use Text instead?


You can change the database type in the mapping:

public class YourDbContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<YourEntityType>().Property(e => e.ModelHash).HasColumnType("TEXT");
    }
}

Or with data annotations

public class YourEntityType
{
    [Column(TypeName = "TEXT")]
    public string ModelHash { get; set; }
}

But I have some suspicion that ModelHash is not your column, is it? It sounds like column from EdmMetadata table and in such case you probably cannot control it this way. That would be either bug in EF or in MySQL connector.

0

精彩评论

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