日常生活的交流与学习

首页 新随笔 联系 管理

SqliteToOracle\global.json

{
  "sdk": {
    "version": "7.0.401"
  }
}

SqliteToOracle\SqliteToOracle.sln


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteToOracle.App", "SqliteToOracle.App\SqliteToOracle.App.csproj", "{F31078FC-6326-4CDA-AA8A-DB3AAF33D029}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteToOracle.Oracle", "SqliteToOracle.Oracle\SqliteToOracle.Oracle.csproj", "{12650F95-B263-402B-A8AF-337DD82072F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteToOracle.StandardBattery", "SqliteToOracle.StandardBattery\SqliteToOracle.StandardBattery.csproj", "{7298432C-9458-4360-A5FF-8938D5B76C01}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{F31078FC-6326-4CDA-AA8A-DB3AAF33D029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{F31078FC-6326-4CDA-AA8A-DB3AAF33D029}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{F31078FC-6326-4CDA-AA8A-DB3AAF33D029}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{F31078FC-6326-4CDA-AA8A-DB3AAF33D029}.Release|Any CPU.Build.0 = Release|Any CPU
		{12650F95-B263-402B-A8AF-337DD82072F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{12650F95-B263-402B-A8AF-337DD82072F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{12650F95-B263-402B-A8AF-337DD82072F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{12650F95-B263-402B-A8AF-337DD82072F5}.Release|Any CPU.Build.0 = Release|Any CPU
		{7298432C-9458-4360-A5FF-8938D5B76C01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{7298432C-9458-4360-A5FF-8938D5B76C01}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{7298432C-9458-4360-A5FF-8938D5B76C01}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{7298432C-9458-4360-A5FF-8938D5B76C01}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
EndGlobal

SqliteToOracle\SqliteToOracle.App\Program.cs

using SqliteToOracle.Oracle.Entities;
using SqliteToOracle.StandardBattery.StandardBatteryContext;

var dbContextStandardBattery = new StandardBatteryContext();


// create dbContextStandardBattery
await dbContextStandardBattery.Database.EnsureCreatedAsync();

var yesterday = DateTime.Today.AddDays(-1);
var yesterdayStart = yesterday; // 00:00:00
var yesterdayEnd = yesterday.AddDays(1).AddSeconds(-1); // 23:59:59

var batteries = dbContextStandardBattery.Batteries
    .Where(b => b.EndTime >= yesterdayStart && b.EndTime <= yesterdayEnd) // filter by date range
    .ToList(); // convert to list


foreach (var battery in batteries)
{
    var batNew = new BatteryOracle { Ip = battery.Ip, Name = battery.Name, StartLevel = battery.StartLevel, StartVoltage = battery.StartVoltage, StartCycle = battery.StartCycle, StartTime = battery.StartTime, Charging = battery.Charging };
    break;
}



// close dbContextStandardBattery
await dbContextStandardBattery.DisposeAsync();





SqliteToOracle\SqliteToOracle.App\SqliteToOracle.App.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <ItemGroup>
    <ProjectReference Include="..\SqliteToOracle.Oracle\SqliteToOracle.Oracle.csproj" />
    <ProjectReference Include="..\SqliteToOracle.StandardBattery\SqliteToOracle.StandardBattery.csproj" />
  </ItemGroup>

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <RestorePackagesPath>packages</RestorePackagesPath>
  </PropertyGroup>

</Project>

SqliteToOracle\SqliteToOracle.Oracle\OracleContext.cs

using Microsoft.EntityFrameworkCore;
using SqliteToOracle.Oracle.Entities;


namespace SqliteToOracle.Oracle.StandardBatteryContext;

public class OracleContext : DbContext
{
    public DbSet<BatteryOracle> Batteries { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            //使用UseOracle方法来指定使用Oracle数据库,并传入连接字符串
            //连接字符串中需要指定数据库用户,密码,服务名等信息
            //使用UseOracleSQLCompatibility方法来指定数据库版本
            optionsBuilder.UseOracle(
                "User Id=<username>;Password=<password>;Data Source=<host>/<port>",
                b => b.UseOracleSQLCompatibility("11"));
        }
    }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<BatteryOracle>().ToTable("STANDARD_BATTERY");
    }
}




SqliteToOracle\SqliteToOracle.Oracle\SqliteToOracle.Oracle.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Oracle.EntityFrameworkCore" Version="7.21.13" />
    <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.130" />
  </ItemGroup>

</Project>


SqliteToOracle\SqliteToOracle.Oracle\Entities\Battery.cs

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;


namespace SqliteToOracle.Oracle.Entities;

public class BatteryOracle
{
      // 使用Guid类型作为主键,并生成一个新的uuid
    [Key]
    [Column("ID")]
    public Guid Id { get; set; } = Guid.NewGuid();

    [Required]
    [Column("IP", TypeName = "VARCHAR2(20)")]
    public string? Ip { get; set; }

    [Column("NAME", TypeName = "VARCHAR2(20)")]
    public string? Name { get; set; }

    [Column("START_LEVEL", TypeName = "FLOAT")]
    public float? StartLevel { get; set; }

    [Column("END_LEVEL", TypeName = "FLOAT")]
    public float? EndLevel { get; set; }

    [Column("START_TEMP", TypeName = "FLOAT")]
    public float?  StartTemp { get; set; }

    [Column("END_TEMP", TypeName = "FLOAT")]
    public float?  EndTemp { get; set; }

    [Column("START_VOLTAGE", TypeName = "FLOAT")]
    public float?  StartVoltage { get; set; }

    [Column("END_VOLTAGE", TypeName = "FLOAT")]
    public float?  EndVoltage { get; set; }

    [Column("START_CYCLE", TypeName = "NUMBER")]
    public int?  StartCycle { get; set; }

    [Column("END_CYCLE", TypeName = "NUMBER")]
    public int?  EndCycle { get; set; }

    [Column("START_TIME", TypeName = "DATE")]
    public DateTime?  StartTime { get; set; }

    [Column("END_TIME", TypeName = "DATE")]
    public DateTime?  EndTime { get; set; }

    [Column("DURATION", TypeName = "NUMBER")]
    public int?  Duration { get; set; }

    [Column("INTERRUPT", TypeName = "NUMBER")]
    public int?  Interrupt { get; set; }

    [Column("CHARGING", TypeName = "NUMBER")]
    public bool Charging { get; set; }
    
}



SqliteToOracle\SqliteToOracle.StandardBattery\SqliteToOracle.StandardBattery.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

SqliteToOracle\SqliteToOracle.StandardBattery\StandardBatteryContext.cs

using Microsoft.EntityFrameworkCore;
using SqliteToOracle.StandardBattery.Entities;


namespace  SqliteToOracle.StandardBattery.StandardBatteryContext;
public class StandardBatteryContext : DbContext
{
    public DbSet<Battery> Batteries { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlite(@"Data Source=F:\song\dotnet_miniapi-main_learn\dotnet_miniapi-main\Dbs\Games.db");
        }
    }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Battery>().ToTable("Batteries");
    }
}




SqliteToOracle\SqliteToOracle.StandardBattery\Entities\Battery.cs

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;


namespace SqliteToOracle.StandardBattery.Entities;

public class Battery
{
    [Key]
    [Column("id")]
    public int Id { get; set; }

    [Required]
    [Column("ip", TypeName = "varchar(20)")]
    public required string Ip { get; set; }

    [Column("name", TypeName = "varchar(20)")]
    public string? Name { get; set; }

    [Column("start_level", TypeName = "float")]
    public float? StartLevel { get; set; }

    [Column("end_level", TypeName = "float")]
    public float? EndLevel { get; set; }

    [Column("start_temp", TypeName = "float")]
    public float?  StartTemp { get; set; }

    [Column("end_temp", TypeName = "float")]
    public float?  EndTemp { get; set; }

    [Column("start_voltage", TypeName = "float")]
    public float?  StartVoltage { get; set; }

    [Column("end_voltage", TypeName = "float")]
    public float?  EndVoltage { get; set; }

    [Column("start_cycle", TypeName = "int")]
    public int?  StartCycle { get; set; }

    [Column("end_cycle", TypeName = "int")]
    public int?  EndCycle { get; set; }

    [Column("start_time", TypeName = "datetime")]
    public DateTime?  StartTime { get; set; }

    [Column("end_time", TypeName = "datetime")]
    public DateTime?  EndTime { get; set; }

    [Column("duration", TypeName = "int")]
    public int?  Duration { get; set; }

    [Column("interrupt", TypeName = "bit")]
    public bool?  Interrupt { get; set; }

    [Column("charging", TypeName = "bit")]
    public bool Charging { get; set; }
    
}


cmd 命令记录导出

doskey /history > history.txt

当前项目的命令记录

dotnet new globaljson

dotnet new sln --output SqliteToOracle
cd SqliteToOracle
dotnet new console --name SqliteToOracle.App
dotnew sln list
dotnet sln add SqliteToOracle.App
dotnet sln list

dotnet new list
dotnet new classlib --name SqliteToOracle.StandardBattery


dotnet new classlib --name SqliteToOracle.Oracle
dotnet sln list

dotnet sln add SqliteToOracle.Oracle
dotnet sln add SqliteToOracle.StandardBattery
dotnet sln list

dotnet add SqliteToOracle.App\SqliteToOracle.App.csproj reference SqliteToOracle.Oracle\SqliteToOracle.Oracle.csproj
dotnet add SqliteToOracle.App\SqliteToOracle.App.csproj reference SqliteToOracle.StandardBattery\SqliteToOracle.StandardBattery.csproj
posted on 2024-01-18 19:30  lazycookie  阅读(12)  评论(0编辑  收藏  举报