Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling complex types in UpdateAll() #100

Open
bernd70 opened this issue Sep 13, 2016 · 0 comments
Open

Handling complex types in UpdateAll() #100

bernd70 opened this issue Sep 13, 2016 · 0 comments

Comments

@bernd70
Copy link

bernd70 commented Sep 13, 2016

Hi,

I encountered a problem when trying to update an value contained in a complex type with UpdateAll(). The generated SQL statement is invalid, the "SET ..." portion is empty.

I tracked it down to GetPropertyName() in ExpressionHelper.cs. Here only the Member name is returned but not its fully qualified name if it is a complex type.

So I adjusted the function to return the fully qualified name of the member. This seems to work for me but since I am not using a lot of EFUtilities functions I am not 100% sure if my change has other (bad :-)) implications.

So here is my code for discussion:

` public static string GetPropertyName<TSource, TProperty>(this Expression<Func<TSource, TProperty>> propertyLambda)
{
Type type = typeof(TSource);

        var temp = propertyLambda.Body;
        while (temp is UnaryExpression)
        {
            temp = (temp as UnaryExpression).Operand;
        }

        return GetFullyQualifiedPropertyName(temp as MemberExpression);
    }

    private static string GetFullyQualifiedPropertyName(MemberExpression member)
    {
        MemberExpression parentMember = member.Expression as MemberExpression;

        if (parentMember != null)
            return GetFullyQualifiedPropertyName(parentMember) + "." + member.Member.Name;

        return member.Member.Name;
    }`

Bernd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant