EF Core MYSQL 生成表映射配置问题
Model表
public class Goods
{
public string ID { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedTime { get; set; }
public string ModifiedBy { get; set; }
public DateTime ModifiedTime { get; set; }
public string GoodsName { get; set; }
public int GoodsNum { get; set; }
}
配置文件
public class GoodsEntityTypeConfiguration : IEntityTypeConfiguration<Goods>
{
public void Configure(EntityTypeBuilder<Goods> builder)
{
builder.ToTable("Sample_Goods_01");
builder.HasKey(ci => ci.ID);
builder.Property(ci => ci.ID).IsRequired();
builder.Property(cb => cb.CreatedBy)
.IsRequired()
.HasMaxLength(20);
builder.Property(cb => cb.CreatedTime)
.IsRequired();
builder.Property(cb => cb.ModifiedBy)
.IsRequired()
.HasMaxLength(20);
builder.Property(cb => cb.GoodsName)
.IsRequired();
builder.Property(cb => cb.GoodsNum)
.IsRequired();
}
}

在MYSQL里,想生成ID保存GUID,开始的时候直接生成 string 生成 text
没有达到我们的效果。ID应该为char(36),CreatedBy 应该为 varchar(20)
应该改为
public class GoodsEntityTypeConfiguration : IEntityTypeConfiguration<Goods>
{
public void Configure(EntityTypeBuilder<Goods> builder)
{
builder.ToTable("Sample_Goods_01");
builder.Property(ci => ci.ID).IsRequired().HasMaxLength(36).HasColumnType("char(36)");
builder.Property(cb => cb.CreatedBy)
.IsRequired()
.HasMaxLength(20).HasColumnType("varchar(20)");
builder.Property(cb => cb.CreatedTime)
.IsRequired();
builder.Property(cb => cb.ModifiedBy)
.IsRequired()
.HasMaxLength(20).HasColumnType("varchar(20)");
builder.Property(cb => cb.GoodsName)
.IsRequired().HasColumnType("varchar(20)");
builder.Property(cb => cb.GoodsNum)
.IsRequired();
}
}

参考:
Jeffcky,EntityFramework Core映射关系详解
MVC - 10.CodeFrist
蝌蝌,EF6(CodeFirst)+MySql开发脱坑指南
EF Core MYSQL 生成表映射配置问题的更多相关文章
- ef.core Mysql
Entity层 using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; ...
- 使用ef core自动生成mysql表和数据编码的问题
mysql默认的编码是不支持中文的,需要改成utf8编码格式. 而我使用的Pomelo.EntityFrameworkCore.MySql组件生成mysql库和表,他是使用默认编码的. 网上大多说修改 ...
- Boolean类型在EF和MySql中的映射关系
MySQL没有Boolean类型.这也是比较奇怪的现象.例: create table xs ( id int primary key, bl boolean ) 这样是可以创建成功,但查看一下建表后 ...
- mysql的表映射
参考博客:https://blog.csdn.net/shushugood/article/details/79925150 1.服务器上的操作 在服务器上mysql创建一个实例,名为test_db, ...
- EF Core MySql GUID配置方式
builder.Property(m => m.Id) .HasColumnName("Id") .ForMySQLHasColumnType("char(36)& ...
- EF Core 2.0中Transaction事务会对DbContext底层创建和关闭数据库连接的行为有所影响
数据库 我们先在SQL Server数据库中建立一个Book表: CREATE TABLE [dbo].[Book]( ,) NOT NULL, ) NULL, ) NULL, ) NULL, [Cr ...
- EntityFramework Core 2.x (ef core) 在迁移中自动生成数据库表和列说明
在项目开发中有没有用过拼音首字母做列名或者接手这样的项目? 看见xmspsqb(项目审批申请表)这种表名时是否有一种无法抑制的想肛了取名的老兄的冲动? 更坑爹的是这种数据库没有文档(或者文档老旧不堪早 ...
- EF Core 2.0 已经支持自动生成父子关系表的实体
现在我们在SQL Server数据库中有Person表如下: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ) NULL, ) NULL, [Cr ...
- EF Core中如何设置数据库表自己与自己的多对多关系
本文的代码基于.NET Core 3.0和EF Core 3.0 有时候在数据库设计中,一个表自己会和自己是多对多关系. 在SQL Server数据库中,现在我们有Person表,代表一个人,建表语句 ...
随机推荐
- Python 标准异常总结
AssertionError 断言语句(assert) AttributeError 尝试访问未知的对象属性 EOFError 用户输入文件末尾标志EOF(Ctrl+d) FloatingPointE ...
- Contains Duplicate I & III
Contains Duplicate I Given an array of integers, find if the array contains any duplicates. Your fun ...
- jquery源码解析
//局部作用域,外部引用不到这个闭合函数里面的东西,这时候需要用提供的对外访问接口来访问里面的变量 (function(){ ; function $() { alert(a) } window.$ ...
- Apollo 代码的编译演示
Apollo 代码的编译演示 官方的文档 -- 运行线下演示 如果你没有车辆及车载硬件, Apollo还提供了一个计算机模拟环境,可用于演示和代码调试. 线下演示需要设置docker的release环 ...
- 029_shell编写工作常用工具类总结
一.检查命令的执行结果 function check_result() { result=$? flag=$1 if [[ "$result"x == "0"x ...
- Laravel 怎么使用资源控制器delete方法
### 在视图上,想删除某个数据,而控制器是使用了resources controller的 那么在删除数据的时候,还是有些需要注意的地方 ### 视图上: <a href="java ...
- response.setContentType()的String参数及对应类型
response.addHeader("Content-Disposition", "attachment;filename="+ filename); res ...
- tcp协议简单了解
HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...
- redhat7.3安装yum源
#检查rehat自带的yum源[root@localhost ~]# rpm -qa | grep yum -.el7.noarch -.el7.noarch -.el7.noarch -.el7.n ...
- LuoGu P1352 没有上司的舞会
题目传送门 这可能是最简单的树形Dp了吧 对于每个人,要么他来,他的下属不来 要么他不来,他的下属爱来不来 于是设计状态: f[i][0/1]表示以i为根的子树中最大能达到的快乐值(i这个人选或者不选 ...