0
点赞
收藏
分享

微信扫一扫

2核2G3M服务器上传速度多少?以阿里云和腾讯云为例

龙毓七七 2023-12-30 阅读 11

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配置字段类型,如下:

生成的

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");
        }
    }
}
举报

相关推荐

0 条评论