Пример #1
0
        private static void CopyPrimaryKeyFields(IObjectContextAdapter context, object from, object to)
        {
            var keyProperties = context.GetPrimaryKeyFieldsFor(from.GetType()).ToList();

            foreach (var keyProperty in keyProperties)
            {
                keyProperty.SetValue(to, keyProperty.GetValue(from, null), null);
            }
        }
Пример #2
0
        private static Expression <Func <T, bool> > CreateKeyPredicateExpression(IObjectContextAdapter context, T entity)
        {
            // get key properties of T
            var keyProperties = context.GetPrimaryKeyFieldsFor(typeof(T)).ToList();

            ParameterExpression parameter  = Expression.Parameter(typeof(T));
            Expression          expression = CreateEqualsExpression(entity, keyProperties[0], parameter);

            for (int i = 1; i < keyProperties.Count; i++)
            {
                expression = Expression.And(expression, CreateEqualsExpression(entity, keyProperties[i], parameter));
            }

            return(Expression.Lambda <Func <T, bool> >(expression, parameter));
        }
Пример #3
0
        private static void CopyPrimaryKeyFields(IObjectContextAdapter context, object from, object to)
        {
            var keyProperties = context.GetPrimaryKeyFieldsFor(from.GetType()).ToList();

            foreach (var keyProperty in keyProperties)
            {
                var value = keyProperty.GetValue(@from, null);
                try
                {
                    keyProperty.SetValue(to, value, null);
                }
                catch (ArgumentException e)
                {
                    throw new NotSupportedException($"Cannot set {from.GetType()}.{keyProperty.Name} - {e.Message}", e);
                }
            }
        }