1、ef中设计成byte[],如下:
/// <summary>
/// 会员证
/// </summary>
public class MemberCard : AuditedEntity<Guid>
{
/// <summary>
/// 企业id
/// </summary>
public Guid CompanyId { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public byte[] ImgUrl { get; set; }
}
使用abp中的dotnet ef migrations add AddTable_MemberCard
生成如下longblob类型:
ImgUrl = table.Column<byte[]>(type: "longblob", nullable: false, comment: "证书图片url"),
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BaseService.Migrations
{
/// <inheritdoc />
public partial class AddTableMemberCard : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "base_MemberCard",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
CompanyId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "企业id", collation: "ascii_general_ci"),
ImgUrl = table.Column<byte[]>(type: "longblob", nullable: false, comment: "证书图片url"),
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_base_MemberCard", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "base_MemberCard");
}
}
}
那咋样才能生成Blob类型的字段呢,其实可以在ef中使用HasColumnType配置字段类型,如下:
builder.Entity<MemberCard>(b =>
{
b.ToTable("base_MemberCard");
b.ConfigureByConvention();b.Property(t => t.CompanyId).HasColumnName("CompanyId").HasComment("企业id").IsRequired();
b.Property(t => t.ImgUrl).HasColumnName("ImgUrl").HasComment("证书图片url").HasColumnType("Blob").IsRequired();
});
生成的
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BaseService.Migrations
{
/// <inheritdoc />
public partial class AddTableMemberCard : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "base_MemberCard",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
CompanyId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "企业id", collation: "ascii_general_ci"),
ImgUrl = table.Column<byte[]>(type: "Blob", nullable: false, comment: "证书图片url"),
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_base_MemberCard", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "base_MemberCard");
}
}
}