Snowflake database provider for Entity Framework Core.
$ dotnet add package EFCore.SnowflakeEntityFrameworkCore.Snowflake is the Entity Framework Core (EF Core) provider for Snowflake.
It is build on top of Snowflake.Data.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Replace with your connection string.
var connectionString = "account=YOUR_ACCOUNT;host=UR_HOST.us-east-1.snowflakecomputing.com;user=UR_USER;password=UR_PASSWORD;db=TESTDB;schema=PUBLIC;warehouse=UR_WAREHOUSE";
// Replace 'YourDbContext' with the name of your own DbContext derived class.
services.AddDbContext<YourDbContext>(
dbContextOptions => dbContextOptions
.UseSnowflake(connectionString)
);
}
}
If you wish to create model from existing Snowflake database, then follow this steps. Provider name is EFCore.Snowflake. Ensure you have ef tools installed (dotnet tool install --global dotnet-ef).
string type with json datapublic class SampleModel
{
public long Id { get; set; }
public string[]? ArrayColumn { get; set; }
}
public class SnowflakeDbContext : DbContext
{
public DbSet<SampleModel> Models { get; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSnowflake();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("PUBLIC");
modelBuilder.Entity<SampleModel>(entity =>
{
entity.ToTable("SAMPLE_MODEL_", "PUBLIC");
entity.HasKey(e => e.Id);
entity.Property(e => e.Id)
.HasColumnType("NUMBER(38,0)")
.HasColumnName("ID");
entity.Property(e => e.ArrayColumn)
.HasColumnType("ARRAY")
.HasColumnName("ARRAY_COLUMN");;
});
}
}
Feel free to submit any feedback - bug reports or feature requests. All feedback is welcome at GitHub repository.
EntityFrameworkCore.Snowflake is released as open source under the GNU Lesser General Public License v3.0 only.