mysql用guid类型,Mysql实体框架上的Guid属性

I'm using Entity Framework with MySql extension on ASP.NET Core application. One of my domain model Message have Guid property and when I want to execute any operation on my DbContext I'm receiving an error: The property 'Message.ID' is of type 'Guid' which is not supported by current database provider. Either change the property CLR type or manually configure the database type for it..

How do I "manually configure the database type'? I've read that it should be mapped for CHAR(36), but I couldn't find how to do that on application side.

@UPDATE

When I set the attribute [Column(TypeName = "char(32)")] to the Guid property, error remains.

This method also does not work

protected override void OnModelCreating(ModelBuilder modelBuilder)

{

var messageEntity = modelBuilder.Entity< Message>();

messageEntity.Property(x => x.ID).

HasAnnotation("Column", new { TypeName = "char(32)" });

}

解决方案

I had this issue and I resolved that way:

I removed the MySql.Data.EntityFrameworkCore from my project

I installed Pomelo.EntityFrameworkCore.MySql by Nuget and this

data provider mapped correctly the Guid.

I changed my method name UseMySQL to UseMySql and added using Microsoft.EntityFrameworkCore; at Startup.cs:

services.AddDbContext(options =>

options.UseMySql(Configuration.GetConnectionString("MyContext")));

Remember to make sure the Guid is data type char(36) in the database.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值