ctripcorp / dal

Ctrip Database Access Layer
Apache License 2.0
1.24k stars 448 forks source link

Column allow null or empty. when using Updatepartly func the ExpressionHelper will be throw error. #17

Closed DaqingFeng closed 7 years ago

DaqingFeng commented 7 years ago

Need Replace the

setValue.Body as MemberExpression;

to

  var member = GetMemberExpression(setValue);

The extend func

    private static MemberExpression GetMemberExpression<TField>(Expression<Func<T, TField>> exp)
        {
            var member = exp.Body as MemberExpression;
            var unary = exp.Body as UnaryExpression;
            return member ?? (unary != null ? unary.Operand as MemberExpression : null);
        }
hejiehui commented 7 years ago

sorry for the late response. which part of dal are you talking about? the client code or the genrated code?

DaqingFeng commented 7 years ago

@hejiehui The code in the client code . please see the detail


namespace Arch.Data.Orm.partially
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T">Indicates table entity</typeparam>
    class ExpressionHelper<T>
    {
........
        public static String GetFieldName<TField>(Expression<Func<T, TField>> setValue)
        {
            if (setValue == null || setValue.Parameters == null || setValue.Parameters.Count == 0)
                throw new DalException("Lambda expression is invalid.");

            var parameter = setValue.Parameters[0];
            if (parameter == null)
                throw new DalException("Lambda expression[{0}] is invalid.", setValue.ToString());

            var member = GetMemberExpression(setValue);  // I extend this func to the logic .

Thanks

wangyenan commented 7 years ago

你可以使用字符串的方式指定coulmn name,如果使用ExpressionHelper,你可以自己修改一下源码,开源版.Net DAL除非遇到重大问题,一般不会再更新了。