private Expression CreateQueryableFunctionQueryRootExpression(
            IDbFunction function, IReadOnlyCollection <Expression> arguments)
        {
            var entityType = _model.FindEntityType(function.MethodInfo.ReturnType.GetGenericArguments()[0]);

            return(new QueryableFunctionQueryRootExpression(entityType, function, arguments));
        }
コード例 #2
0
        public static DataSet GetAsDataSet([NotNull] this IDbFunction dbFunction, [NotNull] Func <dynamic, object> function)
        {
            CodeContracts.ArgumentNotNull(dbFunction, "dbFunction");
            CodeContracts.ArgumentNotNull(function, "function");

            return((DataSet)function(dbFunction.GetDataSet));
        }
コード例 #3
0
        public static DataTable GetAsDataTable([NotNull] this IDbFunction dbFunction, [NotNull] Func <dynamic, object> function)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");
            CodeContracts.VerifyNotNull(function, "function");

            return((DataTable)function(dbFunction.GetData));
        }
コード例 #4
0
ファイル: BasicRepository.cs プロジェクト: wow64bb/YAFNET
 /// <summary>
 /// Initializes a new instance of the <see cref="BasicRepository{T}"/> class.
 /// </summary>
 /// <param name="dbFunction">
 /// The db function.
 /// </param>
 /// <param name="dbAccess">
 /// The db Access.
 /// </param>
 /// <param name="raiseEvent">
 /// The raise Event.
 /// </param>
 /// <param name="haveBoardId">
 /// The have Board Id.
 /// </param>
 public BasicRepository(IDbFunction dbFunction, IDbAccess dbAccess, IRaiseEvent raiseEvent, IHaveBoardID haveBoardId)
 {
     this.DbFunction = dbFunction;
     this.DbAccess   = dbAccess;
     this.DbEvent    = raiseEvent;
     this.BoardID    = haveBoardId.BoardID;
 }
コード例 #5
0
        public static T GetScalar <T>([NotNull] this IDbFunction dbFunction, [NotNull] Func <dynamic, object> function)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");
            CodeContracts.VerifyNotNull(function, "function");

            return(((object)function(dbFunction.Scalar)).ToType <T>());
        }
コード例 #6
0
ファイル: DbFunctionHelpers.cs プロジェクト: ahsan-sally/demo
        /// <summary>
        /// Determines whether [is full text supported].
        /// </summary>
        /// <param name="dbFunction">The database function.</param>
        /// <returns>
        /// Returns if full text is supported by the server or not
        /// </returns>
        public static bool IsFullTextSupported([NotNull] this IDbFunction dbFunction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute(
                       "IsFullTextSupported",
                       f => f.GetScalar <bool>(s => s.IsFullTextSupported())));
        }
コード例 #7
0
        private static T ValidateAndExecute <T>(this IDbFunction dbFunction, string operationName, Func <IDbFunction, T> func)
        {
            if (!dbFunction.DbSpecificFunctions.WhereOperationSupported(operationName).Any())
            {
                throw new InvalidOperationException(@"Database Provider does not support operation ""{0}"".".FormatWith(operationName));
            }

            return(func(dbFunction));
        }
コード例 #8
0
        /// <summary>
        /// The change recovery mode.
        /// </summary>
        /// <param name="dbFunction">
        /// The db function.
        /// </param>
        /// <param name="recoveryMode">
        /// The recovery mode.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ChangeRecoveryMode(
            [NotNull] this IDbFunction dbFunction,
            string recoveryMode)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute(
                       "ChangeRecoveryMode",
                       f => f.Scalar.ChangeRecoveryMode(recoveryMode)));
        }
コード例 #9
0
        /// <summary>
        /// The system initialize fix access.
        /// </summary>
        /// <param name="dbFunction">
        /// The db function.
        /// </param>
        /// <param name="grantAccess">
        /// The grant access.
        /// </param>
        public static void SystemInitializeFixAccess(
            [NotNull] this IDbFunction dbFunction,
            bool grantAccess)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            dbFunction.ValidateAndExecute(
                "SystemInitializeFixAccess",
                f => f.Scalar.SystemInitializeFixAccess(grantAccess));
        }
コード例 #10
0
        //Since this is always generated while compiling there is no query provider associated
        public QueryableFunctionQueryRootExpression(
            [NotNull] IEntityType entityType, [NotNull] IDbFunction function, [NotNull] IReadOnlyCollection <Expression> arguments)
            : base(entityType)
        {
            Check.NotNull(function, nameof(function));
            Check.NotNull(arguments, nameof(arguments));

            Function  = function;
            Arguments = arguments;
        }
コード例 #11
0
        public static IEnumerable <T> GetDataTyped <T>(
            [NotNull] this IDbFunction dbFunction,
            [NotNull] Func <object, object> function,
            [CanBeNull] IEqualityComparer <string> comparer = null) where T : IDataLoadable, new()
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");
            CodeContracts.VerifyNotNull(function, "function");

            return(dbFunction.GetData(function).Typed <T>(comparer));
        }
コード例 #12
0
        /// <summary>
        /// The run sql.
        /// </summary>
        /// <param name="dbFunction">
        /// The db function.
        /// </param>
        /// <param name="sql">
        /// The sql.
        /// </param>
        /// <param name="useTransaction">
        /// The use transaction.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string RunSQL(
            [NotNull] this IDbFunction dbFunction,
            string sql,
            bool useTransaction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute(
                       "RunSQL",
                       f => f.Scalar.RunSQL(sql, useTransaction)));
        }
コード例 #13
0
        /// <summary>
        /// The system initialize execute scripts.
        /// </summary>
        /// <param name="dbFunction">
        /// The db function.
        /// </param>
        /// <param name="script">
        /// The script.
        /// </param>
        /// <param name="scriptFile">
        /// The script file.
        /// </param>
        /// <param name="useTransactions">
        /// The use transactions.
        /// </param>
        public static void SystemInitializeExecuteScripts(
            [NotNull] this IDbFunction dbFunction,
            [NotNull] string script,
            [NotNull] string scriptFile,
            bool useTransactions)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            dbFunction.ValidateAndExecute(
                "SystemInitializeExecuteScripts",
                f => f.Scalar.SystemInitializeExecuteScripts(script, scriptFile, useTransactions));
        }
コード例 #14
0
ファイル: YafDBBroker.cs プロジェクト: bugjohnyang/YAFNET
 /// <summary>
 /// Initializes a new instance of the <see cref="YafDbBroker" /> class.
 /// </summary>
 /// <param name="serviceLocator">The service locator.</param>
 /// <param name="boardSettings">The board settings.</param>
 /// <param name="httpSessionState">The http session state.</param>
 /// <param name="dataCache">The data cache.</param>
 /// <param name="dbFunction">The database function.</param>
 public YafDbBroker(
     IServiceLocator serviceLocator,
     YafBoardSettings boardSettings,
     HttpSessionStateBase httpSessionState,
     IDataCache dataCache,
     IDbFunction dbFunction)
 {
     this.ServiceLocator = serviceLocator;
     this.BoardSettings = boardSettings;
     this.HttpSessionState = httpSessionState;
     this.DataCache = dataCache;
     this.DbFunction = dbFunction;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataBroker" /> class.
 /// </summary>
 /// <param name="serviceLocator">The service locator.</param>
 /// <param name="boardSettings">The board settings.</param>
 /// <param name="httpSessionState">The http session state.</param>
 /// <param name="dataCache">The data cache.</param>
 /// <param name="dbFunction">The database function.</param>
 public DataBroker(
     IServiceLocator serviceLocator,
     BoardSettings boardSettings,
     HttpSessionStateBase httpSessionState,
     IDataCache dataCache,
     IDbFunction dbFunction)
 {
     this.ServiceLocator   = serviceLocator;
     this.BoardSettings    = boardSettings;
     this.HttpSessionState = httpSessionState;
     this.DataCache        = dataCache;
     this.DbFunction       = dbFunction;
 }
コード例 #16
0
        public void DbFunction_IsQueryable()
        {
            var modelBuilder = GetModelBuilder();

            var queryableNoParams
                = typeof(MyDerivedContext)
                  .GetRuntimeMethod(nameof(MyDerivedContext.QueryableNoParams), Array.Empty <Type>());

            IDbFunction function = modelBuilder.HasDbFunction(queryableNoParams).Metadata;

            var model = modelBuilder.FinalizeModel();

            function = model.FindDbFunction(function.ModelName);
            var entityType = model.FindEntityType(typeof(Foo));

            Assert.True(function.IsQueryable);
            Assert.Same(entityType, function.QueryableEntityType);
        }
コード例 #17
0
        public static string ToDebugString(
            [NotNull] this IDbFunction function,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("DbFunction: ");

            builder.Append(function.ReturnType.ShortDisplayName())
            .Append(" ");

            if (function.Schema != null)
            {
                builder
                .Append(function.Schema)
                .Append(".");
            }

            builder.Append(function.Name);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var parameters = function.Parameters.ToList();
                if (parameters.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Parameters: ");
                    foreach (var parameter in parameters)
                    {
                        builder.AppendLine().Append(parameter.ToDebugString(options, indent + 4));
                    }
                }

                if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
                {
                    builder.Append(function.AnnotationsToDebugString(indent: indent + 2));
                }
            }

            return(builder.ToString());
        }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MsSqlSearch"/> class.
 /// </summary>
 /// <param name="dbFunction">The database function.</param>
 public MsSqlSearch(IDbFunction dbFunction)
 {
     this._dbFunction = dbFunction;
 }
コード例 #19
0
 public static void InsertMethod(IDbFunction oIDb)
 {
     oIDb.Insert();
 }
コード例 #20
0
        /// <summary>
        /// Gets the size of the database.
        /// </summary>
        /// <param name="dbFunction">The database function.</param>
        /// <returns>Returns the size of the database</returns>
        public static int GetDBSize([NotNull] this IDbFunction dbFunction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute("DBSize", f => f.GetScalar <int>(s => s.DBSize())));
        }
コード例 #21
0
        /// <summary>
        /// The re index database.
        /// </summary>
        /// <param name="dbFunction">
        /// The db function.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ReIndexDatabase([NotNull] this IDbFunction dbFunction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute("ShrinkDatabase", f => f.GetScalar <string>(s => s.ReIndexDatabase())));
        }
コード例 #22
0
        private void Create(
            IDbFunction function,
            string functionsVariable,
            CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
        {
            if (function.Translation != null)
            {
                throw new InvalidOperationException(RelationalStrings.CompiledModelFunctionTranslation(function.Name));
            }

            if (function is IConventionDbFunction conventionFunction &&
                conventionFunction.GetTypeMappingConfigurationSource() != null)
            {
                throw new InvalidOperationException(RelationalStrings.CompiledModelFunctionTypeMapping(
                                                        function.Name, "Customize()", parameters.ClassName));
            }

            AddNamespace(function.ReturnType, parameters.Namespaces);

            var code             = Dependencies.CSharpHelper;
            var functionVariable = code.Identifier(
                function.MethodInfo?.Name ?? function.Name, parameters.ScopeVariables, capitalize: false);
            var mainBuilder = parameters.MainBuilder;

            mainBuilder
            .Append("var ").Append(functionVariable).AppendLine(" = new RuntimeDbFunction(").IncrementIndent()
            .Append(code.Literal(function.ModelName)).AppendLine(",")
            .Append(parameters.TargetName).AppendLine(",")
            .Append(code.Literal(function.ReturnType)).AppendLine(",")
            .Append(code.Literal(function.Name));

            if (function.Schema != null)
            {
                mainBuilder.AppendLine(",")
                .Append("schema: ").Append(code.Literal(function.Schema));
            }

            if (function.StoreType != null)
            {
                mainBuilder.AppendLine(",")
                .Append("storeType: ").Append(code.Literal(function.StoreType));
            }

            if (function.MethodInfo != null)
            {
                var method = function.MethodInfo;
                mainBuilder.AppendLine(",")
                .Append("methodInfo: ").Append(code.Literal(method.DeclaringType !)).AppendLine(".GetMethod(").IncrementIndent()
                .Append(code.Literal(method.Name !)).AppendLine(",")
                .Append(method.IsPublic ? "BindingFlags.Public" : "BindingFlags.NonPublic")
                .Append(method.IsStatic ? " | BindingFlags.Static" : " | BindingFlags.Instance")
                .AppendLine(" | BindingFlags.DeclaredOnly,")
                .AppendLine("null,")
                .Append("new Type[] { ").Append(string.Join(", ", method.GetParameters().Select(p => code.Literal((Type)p.ParameterType)))).AppendLine(" },")
                .Append("null)").DecrementIndent();
            }

            if (function.IsScalar)
            {
                mainBuilder.AppendLine(",")
                .Append("scalar: ").Append(code.Literal(function.IsScalar));
            }

            if (function.IsAggregate)
            {
                mainBuilder.AppendLine(",")
                .Append("aggregate: ").Append(code.Literal(function.IsAggregate));
            }

            if (function.IsNullable)
            {
                mainBuilder.AppendLine(",")
                .Append("nullable: ").Append(code.Literal(function.IsNullable));
            }

            if (function.IsBuiltIn)
            {
                mainBuilder.AppendLine(",")
                .Append("builtIn: ").Append(code.Literal(function.IsBuiltIn));
            }

            mainBuilder.AppendLine(");").DecrementIndent()
            .AppendLine();

            var parameterParameters = parameters with {
                TargetName = functionVariable
            };

            foreach (var parameter in function.Parameters)
            {
                Create(parameter, parameterParameters);
            }

            CreateAnnotations(
                function,
                Generate,
                parameters with {
                TargetName = functionVariable
            });
コード例 #23
0
ファイル: MsSqlSearch.cs プロジェクト: bugjohnyang/YAFNET
 /// <summary>
 /// Initializes a new instance of the <see cref="MsSqlSearch"/> class.
 /// </summary>
 /// <param name="dbFunction">The database function.</param>
 public MsSqlSearch(IDbFunction dbFunction)
 {
     this._dbFunction = dbFunction;
 }
コード例 #24
0
ファイル: FunctionMapping.cs プロジェクト: ebekker/efcore
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public FunctionMapping(IEntityType entityType, StoreFunction storeFunction, IDbFunction dbFunction, bool includesDerivedTypes)
     : base(entityType, storeFunction, includesDerivedTypes)
 {
     DbFunction = dbFunction;
 }
コード例 #25
0
 private Expression CreateQueryableFunctionQueryRootExpression(
     IDbFunction function, IReadOnlyCollection <Expression> arguments)
 => new QueryableFunctionQueryRootExpression(function.QueryableEntityType, function, arguments);
コード例 #26
0
        /// <summary>
        /// Gets the current SQL Engine Edition.
        /// </summary>
        /// <param name="dbFunction">The database function.</param>
        /// <returns>
        /// Returns the current SQL Engine Edition.
        /// </returns>
        public static string GetSQLEngine([NotNull] this IDbFunction dbFunction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute("GetSQLEngine", f => f.GetScalar <string>(s => s.GetSQLEngine())));
        }
 private Expression CreateTableValuedFunctionQueryRootExpression(
     IDbFunction function, IReadOnlyCollection <Expression> arguments)
 => new TableValuedFunctionQueryRootExpression(function.ReturnEntityType, function, arguments);