using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata;
namespace CoreWebApi_.Models { public partial class DigitalTwinContext : DbContext { public DigitalTwinContext() { }
public DigitalTwinContext(DbContextOptions<DigitalTwinContext> options) : base(options) { }
public virtual DbSet<Node> Nodes { get; set; } = null!; public virtual DbSet<NodesTemp> NodesTemps { get; set; } = null!; public virtual DbSet<View> Views { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. optionsBuilder.UseSqlServer("Data Source=192.168.1.124;Initial Catalog=DigitalTwin;User ID=SA;Password=12345678;Connect Timeout=15"); } }
namespace CoreWebApi_.Models { public partial class Node { public string? Name { get; set; } public string? Descript { get; set; } public string? Tag { get; set; } public string? ItemName { get; set; } public string? ItemDescript { get; set; } public int Id { get; set; } public int ParentId { get; set; } public int? Flag { get; set; } public int? Parent { get; set; } } }
``` C:\Users\惠普\source\repos\CoreWebApi_>dotnet ef dbcontext scaffold --help
Usage: dotnet ef dbcontext scaffold [arguments] [options]
Arguments: <CONNECTION> The connection string to the database. <PROVIDER> The provider to use. (E.g. Microsoft.EntityFrameworkCore.SqlServer)
Options: -d|--data-annotations Use attributes to configure the model (where possible). If omitted, only the fluent API is used. -c|--context <NAME> The name of the DbContext. Defaults to the database name. --context-dir <PATH> The directory to put the DbContext file in. Paths are relative to the project directory. -f|--force Overwrite existing files. -o|--output-dir <PATH> The directory to put files in. Paths are relative to the project directory. --schema <SCHEMA_NAME>... The schemas of tables to generate entity types for. -t|--table <TABLE_NAME>... The tables to generate entity types for. --use-database-names Use table and column names directly from the database. --json Show JSON output. Use with --prefix-output to parse programatically. -n|--namespace <NAMESPACE> The namespace to use. Matches the directory by default. --context-namespace <NAMESPACE> The namespace of the DbContext class. Matches the directory by default. --no-onconfiguring Don't generate DbContext.OnConfiguring. --no-pluralize Don't use the pluralizer. -p|--project <PROJECT> The project to use. Defaults to the current working directory. -s|--startup-project <PROJECT> The startup project to use. Defaults to the current working directory. --framework <FRAMEWORK> The target framework. Defaults to the first one in the project. --configuration <CONFIGURATION> The configuration to use. --runtime <RUNTIME_IDENTIFIER> The runtime to use. --msbuildprojectextensionspath <PATH> The MSBuild project extensions path. Defaults to "obj". --no-build Don't build the project. Intended to be used when the build is up-to-date. -h|--help Show help information -v|--verbose Show verbose output. --no-color Don't colorize output. --prefix-output Prefix output with level.