private void Join(DeleteStatement statement, TableIdentifier table, SchemaMember schema) { if (table == null || schema == null || schema.Token.Property.IsSimplex) { return; } var join = statement.Join(table, schema); var target = (TableIdentifier)join.Target; statement.Tables.Add(target); //生成当前导航属性表的继承链关联集 var joins = this.Join(statement, target, schema.FullPath); if (schema.HasChildren) { foreach (var child in schema.Children) { if (joins != null) { join = joins.FirstOrDefault(j => ((TableIdentifier)j.Target).Entity == child.Token.Property.Entity); if (join != null) { target = (TableIdentifier)join.Target; } } this.Join(statement, target, child); } } }
private TableDefinition BuildMaster(DeleteStatement statement, IEnumerable <SchemaMember> schemas) { var master = TableDefinition.Temporary(); master.Slaves.Add(statement); statement.Returning = new ReturningClause(TableIdentifier.Temporary(master.Name)); foreach (var key in statement.Entity.Key) { master.Field(key); statement.Returning.Fields.Add(statement.Table.CreateField(key)); } var super = statement.Entity.GetBaseEntity(); while (super != null) { this.BuildSlave(master, super); super = super.GetBaseEntity(); } if (schemas != null) { foreach (var schema in schemas) { if (schema.Token.Property.IsSimplex) { continue; } var complex = (IEntityComplexPropertyMetadata)schema.Token.Property; ISource src = null; if (complex.Entity == statement.Entity) { src = statement.Table; } else { src = statement.Join(statement.Table, complex.Entity); } foreach (var link in complex.Links) { //某些导航属性可能与主键相同,表定义的字段定义方法(TableDefinition.Field(...))可避免同名字段的重复定义 if (master.Field(link.Principal) != null) { statement.Returning.Fields.Add(src.CreateField(link.Name)); } } this.BuildSlave(master, schema); } } return(master); }
private void BuildReturning(DeleteStatement statement, IEnumerable <SchemaMember> schemas) { statement.Returning = new ReturningClause(TableDefinition.Temporary()); foreach (var key in statement.Entity.Key) { statement.Returning.Table.Field(key); statement.Returning.Append(statement.Table.CreateField(key), ReturningClause.ReturningMode.Deleted); } var super = statement.Entity.GetBaseEntity(); while (super != null) { this.BuildInherit(statement, super); super = super.GetBaseEntity(); } foreach (var schema in schemas) { if (schema.Token.Property.IsSimplex) { continue; } var complex = (IDataEntityComplexProperty)schema.Token.Property; ISource src = null; if (complex.Entity == statement.Entity) { src = statement.Table; } else { src = statement.Join(statement.Table, complex.Entity); } foreach (var link in complex.Links) { //某些导航属性可能与主键相同,表定义的字段定义方法(TableDefinition.Field(...))可避免同名字段的重复定义 if (statement.Returning.Table.Field(link.Principal) != null) { statement.Returning.Append(src.CreateField(link.Name), ReturningClause.ReturningMode.Deleted); } } this.BuildSlave(statement, schema); } }
private void Join(DeleteStatement statement, TableIdentifier table, SchemaMember schema) { if (table == null || schema == null || schema.Token.Property.IsSimplex) { return; } //不可变复合属性不支持任何写操作,即在删除操作中不能包含不可变复合属性 if (schema.Token.Property.Immutable) { throw new DataException($"The '{schema.FullPath}' is an immutable complex(navigation) property and does not support the delete operation."); } var join = statement.Join(table, schema); var target = (TableIdentifier)join.Target; statement.Tables.Add(target); //生成当前导航属性表的继承链关联集 var joins = this.Join(statement, target, schema.FullPath); if (schema.HasChildren) { foreach (var child in schema.Children) { if (joins != null) { join = joins.FirstOrDefault(j => ((TableIdentifier)j.Target).Entity == child.Token.Property.Entity); if (join != null) { target = (TableIdentifier)join.Target; } } this.Join(statement, target, child); } } }
private void BuildReturning(Aliaser aliaser, DeleteStatement statement, IEnumerable <SchemaMember> schemas) { statement.Returning = new ReturningClause(TableDefinition.Temporary()); foreach (var key in statement.Entity.Key) { statement.Returning.Table.Field(key); statement.Returning.Append(statement.Table.CreateField(key), ReturningClause.ReturningMode.Deleted); } var super = statement.Entity.GetBaseEntity(); while (super != null) { this.BuildInherit(aliaser, statement, super); super = super.GetBaseEntity(); } foreach (var schema in schemas) { if (schema.Token.Property.IsSimplex) { continue; } var complex = (IDataEntityComplexProperty)schema.Token.Property; ISource src = complex.Entity == statement.Entity ? statement.Table : statement.Join(aliaser, statement.Table, complex.Entity); foreach (var link in complex.Links) { var anchors = link.GetAnchors(); if (anchors.Length > 1) { continue; } ISource source = statement.Table; foreach (var anchor in link.GetAnchors()) { if (anchor.IsComplex) { source = statement.Join(aliaser, source, (IDataEntityComplexProperty)anchor); } else { //某些导航属性可能与主键相同,表定义的字段定义方法(TableDefinition.Field(...))可避免同名字段的重复定义 if (statement.Returning.Table.Field((IDataEntitySimplexProperty)anchor) != null) { statement.Returning.Append(src.CreateField(anchor.Name), ReturningClause.ReturningMode.Deleted); } } } } this.BuildSlave(aliaser, statement, schema); } }