当前位置: 首页>>代码示例>>C#>>正文


C# DbModelBuilder.AddFunctions方法代码示例

本文整理汇总了C#中DbModelBuilder.AddFunctions方法的典型用法代码示例。如果您正苦于以下问题:C# DbModelBuilder.AddFunctions方法的具体用法?C# DbModelBuilder.AddFunctions怎么用?C# DbModelBuilder.AddFunctions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbModelBuilder的用法示例。


在下文中一共展示了DbModelBuilder.AddFunctions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddActionsToModel

        /// <summary>	Adds the actions to model. </summary>
        ///
        /// <param name="modelBuilder">		  	The builder that defines the model for the context being
        /// 									created. </param>
        /// <param name="schema">			  	The schema. </param>
        /// <param name="dynamicClassFactory">	The dynamic class factory. </param>
        ///
        /// <returns>	A Type. </returns>
        private static void AddActionsToModel(
            DbModelBuilder modelBuilder,
            DatabaseSchema schema,
            DynamicClassFactory dynamicClassFactory)
        {
            foreach (var function in schema.Functions)
            {
                try
                {
                    if (function.ReturnType != null)
                    {
                        var dynamicMethodData = new DynamicMethodData();
                        dynamicMethodData.FunctionType = FunctionType.ModelDefinedFunction;
                        dynamicMethodData.ReturnType = typeof(Int32);
                        dynamicMethodData.Schema = function.SchemaOwner;
                        if (function.Arguments.Count > 0)
                        {
                            dynamicMethodData.Params = new DynamicParameterData[function.Arguments.Count];
                            for (int i = 0; i < function.Arguments.Count; i++)
                            {
                                dynamicMethodData.Params[i] = new DynamicParameterData()
                                {
                                    Name = function.Arguments[i].Name,
                                    Type = function.Arguments[i].DataType.GetNetType(),
                                    isIn = function.Arguments[i].In,
                                    isOut = function.Arguments[i].Out,
                                    Length = function.Arguments[i].Length
                                };
                            }
                        }
                        _dynamicActionMethods.Add(function.Name, dynamicMethodData);
                    }
                }
                catch (Exception exception)
                {
                    DynamicLogger.Instance.WriteLoggerLogError("AddActionsToModel", exception);
                }
            }

            foreach (var procedure in schema.StoredProcedures)
            {
                try
                {
                    var dynamicMethodData = new DynamicMethodData();
                    dynamicMethodData.FunctionType = FunctionType.ModelDefinedFunction;
                    dynamicMethodData.ReturnType = typeof(Int32);
                    dynamicMethodData.Schema = procedure.SchemaOwner;
                    if (procedure.Arguments.Count > 0)
                    {
                        dynamicMethodData.Params = new DynamicParameterData[procedure.Arguments.Count];
                        for (int i = 0; i < procedure.Arguments.Count; i++)
                        {
                            dynamicMethodData.Params[i] = new DynamicParameterData()
                            {
                                Name = procedure.Arguments[i].Name,
                                Type = procedure.Arguments[i].DataType.GetNetType(),
                                isIn = procedure.Arguments[i].In,
                                isOut = procedure.Arguments[i].Out,
                                Length = procedure.Arguments[i].Length
                            };
                        }
                    }
                    _dynamicActionMethods.Add(procedure.Name, dynamicMethodData);
                }
                catch (Exception exception)
                {
                    DynamicLogger.Instance.WriteLoggerLogError("AddActionsToModel", exception);
                }
            }

            try
            {
                _dynamicActions = CreateTypeAction(dynamicClassFactory, "DbActions", _dynamicActionMethods);
                // https://www.nuget.org/packages/EntityFramework.Functions
                modelBuilder.AddFunctions(_dynamicActions, false);
            }
            catch (Exception exception)
            {
                DynamicLogger.Instance.WriteLoggerLogError("AddActionsToModel", exception);
            }
        }
开发者ID:arcelormittalkriviyrih,项目名称:odata_unified_svc,代码行数:89,代码来源:DynamicContext.cs


注:本文中的DbModelBuilder.AddFunctions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。