EF framework 추가

hhsung_work
hhsung 10 months ago
parent 14a46fbf90
commit c007128dee

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace SmartAquaViewer.DataAnalisys
{
public class AppDbContext : DbContext
{
//dotnet ef migrations add InitialCreate
//dotnet ef database update
//dotnet ef migrations add AddMultipleTables
//dotnet ef database update
public DbSet<WaterQualityVO> WaterQualities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// SQL Server 예시 (필요에 맞게 변경)
optionsBuilder.UseSqlServer(
"Server=localhost;Database=SmartAquaDB;Trusted_Connection=True;TrustServerCertificate=True;");
}
}
}

@ -9,13 +9,15 @@ namespace SmartAquaViewer.DataAnalisys
{
internal class AquarDataControl
{
private AQUA_DATA_CONTROL_STATE state = AQUA_DATA_CONTROL_STATE.IDLE;
private readonly IWaterQuality iwaterQuality;
private CancellationTokenSource? cts;
AppDbContext db = new AppDbContext();
public AquarDataControl(IWaterQuality iwaterQuality)
{
this.iwaterQuality = iwaterQuality;
@ -65,6 +67,7 @@ namespace SmartAquaViewer.DataAnalisys
vo.Timestamp = DateTime.Now;
iwaterQuality.OnParsed(vo);
db.Add(vo);
iwaterQuality.OnProgress(percent);
}

@ -19,6 +19,7 @@ namespace SmartAquaViewer.DataAnalisys
internal interface IWaterQuality
{
void OnParsed(WaterQualityVO vo);
void OnProgress(double percent);
void OnError(string message);
void OnCompleted();

@ -9,9 +9,17 @@ namespace SmartAquaViewer.DataAnalisys
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("WaterQuality")]
public class WaterQualityVO
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] // 자동 증가
public int Id { get; set; } // PK, Auto Increment
/// <summary>
/// 저수조 번호
/// </summary>

@ -8,4 +8,14 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

Loading…
Cancel
Save