示例#1
0
        public static IValueInsertable <T> Value <T, TV>(
            [NotNull]                this IValueInsertable <T> source,
            [NotNull, InstantHandle] Expression <Func <T, TV> > field,
            TV value)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            var query = ((ValueInsertable <T>)source).Query;

            var q = query.Provider.CreateQuery <T>(
                Expression.Call(
                    null,
                    _valueMethodInfo4.MakeGenericMethod(new[] { typeof(T), typeof(TV) }),
                    new[] { query.Expression, Expression.Quote(field), Expression.Constant(value, typeof(TV)) }));

            return(new ValueInsertable <T> {
                Query = q
            });
        }
示例#2
0
        public static IValueInsertable <T> Value <T, TV>(
            [NotNull] this IValueInsertable <T> source,
            [NotNull] Expression <Func <T, TV> > field,
            [NotNull] Expression <Func <TV> > value)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var query = ((ValueInsertable <T>)source).Query;

            var q = query.Provider.CreateQuery <T>(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(new[] { typeof(T), typeof(TV) }),
                    new[] { query.Expression, Expression.Quote(field), Expression.Quote(value) }));

            return(new ValueInsertable <T> {
                Query = q
            });
        }
示例#3
0
        public static object InsertWithIdentity <T>([NotNull] this IValueInsertable <T> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var query = ((ValueInsertable <T>)source).Query;

            return(query.Provider.Execute <object>(
                       Expression.Call(
                           null,
                           _insertWithIdentityMethodInfo2.MakeGenericMethod(typeof(T)), query.Expression)));
        }
示例#4
0
        public static int Insert <T>([NotNull] this IValueInsertable <T> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var query = ((ValueInsertable <T>)source).Query;

            return(query.Provider.Execute <int>(
                       Expression.Call(
                           null,
                           _insertMethodInfo2.MakeGenericMethod(new[] { typeof(T) }),
                           new[] { query.Expression })));
        }
示例#5
0
        public static object InsertWithIdentity <T>([NotNull] this IValueInsertable <T> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var query = ((ValueInsertable <T>)source).Query;

            return(query.Provider.Execute <object>(
                       Expression.Call(
                           null,
                           ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(new[] { typeof(T) }),
                           new[] { query.Expression })));
        }
示例#6
0
 /// <summary>
 /// This is internal API and is not intended for use by Linq To DB applications.
 /// It may change or be removed without further notice.
 /// </summary>
 public static IDataContext GetDataContext <T>(IValueInsertable <T> insertable)
 {
     return(GetDataContext(((LinqExtensions.ValueInsertable <T>)insertable).Query));
 }