Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public void Configure(EntityTypeBuilder<TCronTicker> builder)
.HasDatabaseName("IX_Function_Expression");

builder.Property(e => e.IsEnabled)
.IsRequired()
.HasDefaultValueSql("1")
.HasSentinel(true);
.IsRequired();

builder.ToTable("CronTickers", _schema);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

using TickerQ.EntityFrameworkCore.Configurations;
using TickerQ.Utilities.Entities;

namespace TickerQ.EntityFrameworkCore.Tests.Infrastructure;
Expand Down Expand Up @@ -33,18 +31,22 @@ public async Task DisposeAsync()
}

[Fact]
public void IsEnabled_Uses_DefaultValueSql_Not_DefaultValue()
public void IsEnabled_Has_No_Database_Default()
{
var entityType = _context.Model.FindEntityType(typeof(CronTickerEntity))!;
var property = entityType.FindProperty(nameof(CronTickerEntity.IsEnabled))!;

// HasDefaultValueSql sets the relational default SQL, not the CLR default value
var relational = property.GetDefaultValueSql();
Assert.Equal("1", relational);
// No database default — the CLR property initializer (= true) handles the default.
// This avoids any provider-specific SQL translation concerns.
Assert.Equal(ValueGenerated.Never, property.ValueGenerated);
Assert.Null(property.GetDefaultValueSql());
}

// The sentinel is set to true so EF Core sends false explicitly
var sentinel = property.Sentinel;
Assert.Equal(true, sentinel);
[Fact]
public void IsEnabled_CLR_Default_Is_True()
{
var entity = new CronTickerEntity();
Assert.True(entity.IsEnabled);
}

[Fact]
Expand All @@ -59,8 +61,8 @@ public void IsEnabled_Is_Required()
[Fact]
public async Task Insert_CronTicker_Without_IsEnabled_Gets_Default_True()
{
// The C# property initializer sets IsEnabled = true,
// and the database default is 1 — both paths produce true.
// The C# property initializer sets IsEnabled = true;
// EF Core always includes it in the INSERT — no DB default needed.
var ticker = new CronTickerEntity
{
Id = Guid.NewGuid(),
Expand Down
Loading