首页 > 解决方案 > 有没有办法使用 Visual Studio 或 SQLite 数据库中的其他工具创建 EF 映射类?

问题描述

这是我不久前为 SQL Server 创建的一个。但我现在需要类似的新 SQLite 数据库。

    public TopicMap()
    {
        // Primary Key
        this.HasKey(t => t.TopicId);

        // Identity
        this.Property(t => t.TopicId)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

        // Properties
        this.Property(t => t.Name)
            .IsRequired()
            .HasMaxLength(255);

        this.Property(t => t.Number)
            .IsRequired();

        this.Property(t => t.Version)
            .IsRequired()
            .IsFixedLength()
            .HasMaxLength(8)
            .IsRowVersion();

        // Table & Column Mappings
        this.ToTable("Topic");
        this.Property(t => t.TopicId).HasColumnName("TopicId");
        this.Property(t => t.Number).HasColumnName("Number");
        this.Property(t => t.Name).HasColumnName("Name");
        this.Property(t => t.SubjectId).HasColumnName("SubjectId");
        this.Property(t => t.Version).HasColumnName("Version");
        this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
        this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");
        this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");
        this.Property(t => t.ModifiedDate).HasColumnName("ModifiedDate");
        this.Property(t => t.Created).HasColumnName("Created");
        this.Property(t => t.Modified).HasColumnName("Modified");

        // Relationships
        this.HasRequired(t => t.Subject)
            .WithMany(t => t.Topics)
            .HasForeignKey(d => d.SubjectId)
            .WillCascadeOnDelete(false);

    }

我现在有一个复杂的 SQLite 数据库,但根本找不到任何可以自动创建模型和映射类的工具。

有谁知道存在的任何东西?

标签: entity-frameworksqliteentity-framework-core

解决方案


借助 EF Core,您可以使用 EF Core Power Tools。您必须安装 SQLite Visual Studio 工具。

更多信息:https ://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering


推荐阅读