You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following where I create a sequence and set the default value of some property to an SQL User Defined Function call
protectedoverridevoidOnModelCreating(ModelBuilderbuilder){base.OnModelCreating(builder);
builder.HasSequence<long>("HumanIdSeq");
builder.Entity<Order>().Property(o => o.Reference).ValueGeneratedOnAdd().HasDefaultValueSql("dbo.GenerateHumanId(NEXT VALUE FOR HumanIdSeq)");}
Given that I don't need to call my function from c# how can I create it as raw SQL using the ModelBuilder?
the only way I found is to modify the migration file and define my function as raw SQL there using the MigrationBuilder, is there a way to avoid this step and define it as raw SQL in the ModelBuilder?
The text was updated successfully, but these errors were encountered:
Assuming you're using migrations, then yeah, the way to do this is to specify the raw SQL in your migration file (as in the docs). It currently isn't possible to define raw SQL to be run in model building without migrations - your only option is to include it in your migration file (or to run it outside of EF Core).
BTW I briefly mentioned specifying raw SQL without migrations back in the day in #6524 (comment), but I don't think we have a proper tracking issue). This wouldn't be trivial - it's easy enough to run the raw SQL on EnsureCreated, but if migrations are being used it's not clear what to do when the SQL changes...
Consider the following where I create a sequence and set the default value of some property to an SQL User Defined Function call
Given that I don't need to call my function from c# how can I create it as raw SQL using the ModelBuilder?
the only way I found is to modify the migration file and define my function as raw SQL there using the MigrationBuilder, is there a way to avoid this step and define it as raw SQL in the ModelBuilder?
The text was updated successfully, but these errors were encountered: