-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Forecast Summary and DbContext design time
- Loading branch information
Alejandro Del Rincón López
committed
Sep 28, 2023
1 parent
f0fccaa
commit 7ef3dc1
Showing
6 changed files
with
213 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace BlazorApp1.Domain; | ||
|
||
public class WeatherForecastSummary | ||
{ | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public DateOnly Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)Math.Round(TemperatureC / 0.5556, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
|
||
namespace BlazorApp1.Data.Design; | ||
|
||
public class WeatherDbContextFactory : IDesignTimeDbContextFactory<WeatherDbContext> | ||
{ | ||
public WeatherDbContext CreateDbContext(string[] args) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder<WeatherDbContext>(); | ||
optionsBuilder.UseSqlite("Data Source=Local.sqlite"); | ||
|
||
return new WeatherDbContext(optionsBuilder.Options); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
BlazorApp1/Shared/Migrations/20230928075811_Summaries.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace BlazorApp1.Shared.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Summaries : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "ForecastSummaries", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "INTEGER", nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
Date = table.Column<DateOnly>(type: "TEXT", nullable: false), | ||
TemperatureC = table.Column<int>(type: "INTEGER", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_ForecastSummaries", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_ForecastSummaries_Date", | ||
table: "ForecastSummaries", | ||
column: "Date", | ||
unique: true); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "ForecastSummaries"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters