ABP的Core2.0使用mysql数据,在使用linq语句报错了

2019-01-02 20:23发布

问题:

好像时mysql的bool类型与linq有问题 ,有谁有这样的错吗,

下面的错时在初始化数据的时候,在执行linq语句就报错了

No coercion operator is defined between types 'System.Int16' and 'System.Boo

有哪位大佬知道怎么解决吗?

 

 

 

 

 1 migrationBuilder.CreateTable(
 2                 name: "AbpEditions",
 3                 columns: table => new
 4                 {
 5                     Id = table.Column<int>(nullable: false)
 6                         .Annotation("MySQL:AutoIncrement", true),
 7                     CreationTime = table.Column<DateTime>(nullable: false),
 8                     CreatorUserId = table.Column<long>(nullable: true),
 9                     LastModificationTime = table.Column<DateTime>(nullable: true),
10                     LastModifierUserId = table.Column<long>(nullable: true),
11                     IsDeleted = table.Column<short>(nullable: false),
12                     DeleterUserId = table.Column<long>(nullable: true),
13                     DeletionTime = table.Column<DateTime>(nullable: true),
14                     Name = table.Column<string>(maxLength: 32, nullable: false),
15                     DisplayName = table.Column<string>(maxLength: 64, nullable: false)
16                 },
17                 constraints: table =>
18                 {
19                     table.PrimaryKey("PK_AbpEditions", x => x.Id);
20                 });
View Code
 1             modelBuilder.Entity("Abp.Application.Editions.Edition", b =>
 2                 {
 3                     b.Property<int>("Id")
 4                         .ValueGeneratedOnAdd();
 5 
 6                     b.Property<DateTime>("CreationTime");
 7 
 8                     b.Property<long?>("CreatorUserId");
 9 
10                     b.Property<long?>("DeleterUserId");
11 
12                     b.Property<DateTime?>("DeletionTime");
13 
14                     b.Property<string>("DisplayName")
15                         .IsRequired()
16                         .HasMaxLength(64);
17 
18                     b.Property<bool>("IsDeleted");
19 
20                     b.Property<DateTime?>("LastModificationTime");
21 
22                     b.Property<long?>("LastModifierUserId");
23 
24                     b.Property<string>("Name")
25                         .IsRequired()
26                         .HasMaxLength(32);
27 
28                     b.HasKey("Id");
29 
30                     b.ToTable("AbpEditions");
31                 });
View Code

执行下面的linq就报错了

 1  private void CreateEditions()
 2             {
 3                 var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
 4                 if (defaultEdition == null)
 5                 {
 6                     defaultEdition = new Edition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName };
 7                     _context.Editions.Add(defaultEdition);
 8                     _context.SaveChanges();
 9 
10                     /* Add desired features to the standard edition, if wanted... */
11                 }
12             }
View Code

 

回答1:

连接串: Data Source=IP;port=3306;Initial Catalog=hans;user id=root;password=***;charset=gbk;allow zero datetime=True;convert zero datetime=True;SslMode = none;

allow zero datetime=True;convert zero datetime=True; 就是这这个换换失败了 去掉就可以了

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



回答2:

看一下你的实体定义,bit对应的是bool类型。



回答3:

IsDeleted = table.Column<short>(nullable: false) 怎么是 short ?



标签: