public virtual void SetTable(ISqlBuilder sqlBuilder, MappingSchema mappingSchema, SqlTable table, MethodCallExpression methodCall, Func <Expression, ColumnDescriptor?, ISqlExpression> converter) { table.SqlTableType = SqlTableType.Function; table.Name = Name ?? methodCall.Method.Name; table.PhysicalName = Name ?? methodCall.Method.Name; var expressionStr = table.Name; ExpressionAttribute.PrepareParameterValues(methodCall, ref expressionStr, false, out var knownExpressions, out var genericTypes); if (string.IsNullOrEmpty(expressionStr)) { throw new LinqToDBException($"Cannot retrieve Table Function body from expression '{methodCall}'."); } // Add two fake expressions, TableName and Alias knownExpressions.Insert(0, null); knownExpressions.Insert(0, null); table.TableArguments = ExpressionAttribute.PrepareArguments(expressionStr !, ArgIndices, addDefault: true, knownExpressions, genericTypes, converter).Skip(2).ToArray(); if (Schema != null) { table.Schema = Schema; } if (Database != null) { table.Database = Database; } if (Server != null) { table.Server = Server; } }
public virtual void SetTable <TContext>(TContext context, ISqlBuilder sqlBuilder, MappingSchema mappingSchema, SqlTable table, MethodCallExpression methodCall, Func <TContext, Expression, ColumnDescriptor?, ISqlExpression> converter) { table.SqlTableType = SqlTableType.Function; var expressionStr = table.Expression = Name ?? methodCall.Method.Name !; ExpressionAttribute.PrepareParameterValues(methodCall, ref expressionStr, false, out var knownExpressions, false, out var genericTypes); if (string.IsNullOrEmpty(expressionStr)) { throw new LinqToDBException($"Cannot retrieve Table Function body from expression '{methodCall}'."); } table.TableName = new SqlObjectName( expressionStr !, Schema: Schema ?? table.TableName.Schema, Database: Database ?? table.TableName.Database, Server: Server ?? table.TableName.Server, Package: Package ?? table.TableName.Package); table.TableArguments = ExpressionAttribute.PrepareArguments(context, string.Empty, ArgIndices, true, knownExpressions, genericTypes, converter); }