Pomelo.EntityFrameworkCore.MySQL DBContext throwing “Unqualified data type char” exception

寵の児 提交于 2019-12-25 00:55:26

问题


I am trying to port an existing application from EF 6 and MySQL.Data.Entity.EF6 to EF Core and Pomelo.EntityFrameworkCore.MySql.

When the DBContext creates its model, it throws an ArgumentException with message "Unqualified data type char."

I can reproduce the error in a brand-new Console project. As soon as I add a DBSet<Site> to my DBContext, where Site is a class from my existing project's Database.Entities dll, the validation error appears.

Abbreviated stack trace:

   at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlTypeMappingSource.ValidateMapping(CoreTypeMapping mapping, IProperty property)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList`1 principals)
   ...
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   ...
   at Microsoft.EntityFrameworkCore.DbContext.get_Model()

The existing class is pretty simple. It looks like this (actually, the Id is inherited from a base class):

public class Site {
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [Required]
    public string Id { get; set; }

    [Required]
    public string Name { get; set; }

    [ForeignKey("ApplicationId")]
    public virtual Application Application { get; set; }
    [Column("ApplicationId")]
    [Required]
    public string ApplicationId { get; set; }
}

Is there something about the way the existing Dll is compiled that affects this? Can I override something in OnModelCreating to avoid this error? Is there any way to get further insight into what property is being seen as "char"?

来源:https://stackoverflow.com/questions/57662470/pomelo-entityframeworkcore-mysql-dbcontext-throwing-unqualified-data-type-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!