How do I avoid the inserted object being selected after insertion in EF Core?

I have a lot of attachments that are just for logging purposes in Azure DB and I can see that now most of the DTU usage is taken by this logging.

The loading of the database is not due to the insert itself, but due to the fact that after insertion, but because the field CreationDate

is created by the database and EFCore fetches it after insertion.

To solve the conversion of "datetime2" errors, I defined the field CreationDate

asentity.Property(e => e.CreationDate).HasColumnType("datetime").HasDefaultValueSql("getdate()");

So EF calls the DB after the insert:

(@p0 uniqueidentifier)SELECT [CreationDate]
FROM [MyLogs]
WHERE @@ROWCOUNT = 1 AND [Id] = @p0

      

Is there a way to avoid this behavior and just let the object not be tracked after insertion?

Now the only way I can see is to ignore the CreationDate field from the entity model since it is not being used. entity.Ignore(e => e.CreationDate);

+3


source to share





All Articles