File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ public override void Configure(IFunctionsHostBuilder builder)
1616 builder . Services . AddDbContext < TodoContext > (
1717 options => options . UseSqlServer ( connectionString )
1818 ) ;
19- }
20-
19+ }
2120 }
2221}
Original file line number Diff line number Diff line change 1313using System . Data ;
1414using Microsoft . Data . SqlClient ;
1515using Microsoft . EntityFrameworkCore ;
16+ using Microsoft . EntityFrameworkCore . Design ;
1617using System . ComponentModel . DataAnnotations . Schema ;
17- using Dapper ;
1818
1919namespace Todo . Backend . EFCore
2020{
@@ -36,6 +36,7 @@ public class TodoContext : DbContext
3636 public TodoContext ( DbContextOptions < TodoContext > options )
3737 : base ( options )
3838 { }
39+
3940 protected override void OnModelCreating ( ModelBuilder modelBuilder )
4041 {
4142 modelBuilder . HasSequence < int > ( "global_sequence" ) ;
@@ -44,15 +45,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4445 . Property ( o => o . Id )
4546 . HasDefaultValueSql ( "NEXT VALUE FOR global_sequence" ) ;
4647 }
48+
4749 protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
4850 => optionsBuilder
4951 . LogTo ( Console . WriteLine , LogLevel . Information )
5052 . EnableSensitiveDataLogging ( )
5153 . EnableDetailedErrors ( ) ;
52-
54+
5355 public DbSet < Todo > Todos { get ; set ; }
5456 }
5557
58+ public class TodoContextFactory : IDesignTimeDbContextFactory < TodoContext >
59+ {
60+ public TodoContext CreateDbContext ( string [ ] args )
61+ {
62+ var optionsBuilder = new DbContextOptionsBuilder < TodoContext > ( ) ;
63+ optionsBuilder . UseSqlServer ( Environment . GetEnvironmentVariable ( "AzureSQL" ) ) ;
64+
65+ return new TodoContext ( optionsBuilder . Options ) ;
66+ }
67+ }
68+
5669 public class ToDoHandler
5770 {
5871 private TodoContext _todoContext ;
Original file line number Diff line number Diff line change 77 <PackageReference Include =" Dapper" Version =" 2.0.123" />
88 <PackageReference Include =" Microsoft.Azure.Functions.Extensions" Version =" 1.1.0" />
99 <PackageReference Include =" Microsoft.Data.SqlClient" Version =" 4.1.0" />
10+ <PackageReference Include =" Microsoft.EntityFrameworkCore.Design" Version =" 6.0.10" >
11+ <IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
12+ <PrivateAssets >all</PrivateAssets >
13+ </PackageReference >
1014 <PackageReference Include =" Microsoft.EntityFrameworkCore.SqlServer" Version =" 6.0.10" />
1115 <PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 6.0.1" />
1216 <PackageReference Include =" Microsoft.NET.Sdk.Functions" Version =" 4.0.1" />
You can’t perform that action at this time.
0 commit comments