FlexLabs.Upsert icon indicating copy to clipboard operation
FlexLabs.Upsert copied to clipboard

Support for passing in types that do not match exact entity type

Open tsf9810292 opened this issue 2 years ago • 0 comments

While the change in this PR is working great for my use case, am definitely open to other suggestions to accomplish something similar.

In general what I am trying to support is having more dynamic code that uses Upsert, allowing the ability to either passing in just object, or possibly a parent class like "MyBaseEntity". Here is some pseudo code this change allows me to run:

foreach (var syncObject in SyncObjects)
{
    var enityType = Type.GetType(syncObject.FullTypeName);

    foreach (var record in syncObject.Records)
    {
        var entity = JsonSerializer.Deserialize((JsonElement)record, enityType);

        _dbContext.Upsert(entity).Run();
    }
}

tsf9810292 avatar Apr 06 '22 20:04 tsf9810292