【发布时间】:2019-11-18 11:29:11
【问题描述】:
我遇到了“无法识别的 Guid 格式”的问题。在尝试查找集合中的数据时。 应用程序适用于 .Net 4.5 和 EF6。我正面临这个问题,因为我们从 MsSql 切换到 MySql Db。
实体看起来像:
public abstract class DomainEntity(){
public Guid Id { get; protected set; };
public bool IsActive { get; protected set; }
public DateTime CreateTime { get; set; }
public DateTime ModifyTime { get; set; }
}
数据库表如下所示:
CREATE TABLE IF NOT EXISTS `MssDocumentsDb`.`dbo_Versionings` (
`Id` CHAR(36) UNIQUE NOT NULL,
`IsActive` TINYINT(1) NOT NULL DEFAULT 1,
`CreateTime` DATETIME(6) NOT NULL,
`ModifyTime` DATETIME(6) NOT NULL,
PRIMARY KEY (`Id`));
让大多数数据正常工作,但有时我会遇到“无法识别的 Guid 格式”的问题。
最常发生该错误的地方如下所示:
public virtual TEntity Get(Guid Id)
=> Id != Guid.Empty ? GetSet().Find(Id) : null;
创建集:
public IDbSet<TEntity> CreateSet<TEntity>()
where TEntity : class => base.Set<TEntity>();
我尝试了不同的解决方案来解决这个问题。 尝试将 db 中的 Id 从 CHAR(36) 切换到 varchar(64),传递 Id.ToSting() 或将 'Old Guids=true' 添加到连接字符串,但没有结果。
感谢您的帮助。
【问题讨论】:
-
您的一个 ID 不是 GUID 格式。
-
@mjwills ,感谢您的方法,我将检查表格中的数据并返回结果。
标签: c# mysql entity-framework guid