Skip to content

Dictionary exception is thrown in EFCore.BulkExtensions.PostgreSql/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs #1906

@arkont

Description

@arkont

EFCore.BulkExtensions.PostgreSql/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs

The function:
static object? GetPropertyValue(DbContext context, TableInfo tableInfo, string propertyName, T entity)

Throw exception due to value is not found in dictionary

The problem in the function is follow part:

        object? propertyValue = entity;
        string fullPropertyName = string.Empty;
        foreach (var entry in propertyName.AsSpan().Split("."))
        {
            if (propertyValue == null)
            {
                return null;
            }

            if (fullPropertyName.Length > 0)
            {
                fullPropertyName += $"_{entry.ToString()}";
            }
            else
            {
                fullPropertyName = new string(entry.ToString());
            }

            propertyValue = tableInfo.FastPropertyDict[fullPropertyName].Get(propertyValue);
        }
        return propertyValue;

Eg propertyName is "id"
var entry in propertyName.AsSpan().Split(".") generates a range object and range object to string in follow code
fullPropertyName = new string(entry.ToString()); gives "[0..2] not "id"

I made follow change to the code just to get it to work.
foreach (var entry in propertyName.Split(".").AsSpan())

However I dont know what other implication it will give for more complex projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions