-
Couldn't load subscription status.
- Fork 3.3k
Labels
area-model-buildingcustomer-reportedgood first issueThis issue should be relatively straightforward to fix.This issue should be relatively straightforward to fix.
Milestone
Description
Unable to set default value for interfaces/generics.
Not working:
Model:
public class EventTriggers
{
public IEnumerable<Regex> Triggers { get; private set; }
}Context Configuration:
builder.OwnsOne(t => t.EventTriggers, trigger =>
{
trigger.Property(p => p.Triggers)
.HasConversion<string>(
to => to.SerializeToJson(Newtonsoft.Json.Formatting.None, true),
from => from.DeserializeFromJson<IEnumerable<Regex>>())
.HasDefaultValue(Enumerable.Empty<Regex>());
});Results in the following when running add-migration:
Cannot set default value 'System.Text.RegularExpressions.Regex[]' of type 'System.Text.RegularExpressions.Regex[]' on property 'Triggers' of type 'System.Collections.Generic.IEnumerable`1[System.Text.RegularExpressions.Regex]' in entity type 'EventTriggers'.
The following is working:
Model:
public class EventTriggers
{
public List<Regex> Triggers { get; private set; }
}Context Configuration:
builder.OwnsOne(t => t.EventTriggers, trigger =>
{
trigger.Property(p => p.Triggers)
.HasConversion<string>(
to => to.SerializeToJson(Newtonsoft.Json.Formatting.None, true),
from => from.DeserializeFromJson<List<Regex>>())
.HasDefaultValue(new List<Regex>());
});Is this by design?
EF Core version: 2.2.6
Database provider: npgsql
Target framework: (e.g. .NET Core 2.2)
Operating system: Cross Platform
IDE: VS 2019
Metadata
Metadata
Assignees
Labels
area-model-buildingcustomer-reportedgood first issueThis issue should be relatively straightforward to fix.This issue should be relatively straightforward to fix.