N
N
netcore2020-05-21 07:12:59
.NET
netcore, 2020-05-21 07:12:59

Why doesn't In Memory Database autogenerate int property?

In Memory Database doesn't autogenerate int property, huh?
Trying to sequence a simple int value builder.Property

(x => x.SerialNumber).ValueGeneratedOnAdd()

after AddAsync() - 0

.net Core 3.1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
netcore, 2020-05-21
@netcore

Decided differently in OnModelBuilding

if (DataBase.IsInMemory())
var autoGenIntProperties = modelBuilder.Model.GetEntityTypes()
                .SelectMany(t => t.GetProperties())
                .Where(p => p.ClrType == typeof(int) && p.ValueGenerated != ValueGenerated.Never);

            foreach (var property in autoGenIntProperties)
                property.SetValueGeneratorFactory((p, t) => new InMemoryIntegerValueGenerator<int>(p.GetIndex()));

This is most likely because:
1. The keys are clear how to increment, but there are no custom fields
2. Each database has a different implementation of this case, so you need to explicitly specify in InMemory how to win back this
case initialization, so that users do not rack their brains for hours

V
Vladimir Korotenko, 2020-05-21
@firedragon

Try this solution.
https://stackoverflow.com/questions/47754939/how-t...
Other than that it looks like the problem is reoccurring, read the advice here in this thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question