Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void TreeCreated(DbCommandTreeInterceptionContext interceptionContext)
- {
- if (interceptionContext.Result.DataSpace == DataSpace.SSpace)
- {
- var insertCommand = interceptionContext.Result as DbInsertCommandTree;
- if (insertCommand != null)
- {
- var column = ColumnAnnotationAttribute.GetColumnName<HierarchicalPathAttribute>(insertCommand.Target.VariableType.EdmType);
- var clauses = insertCommand.SetClauses.ToList();
- if (column != null)
- {
- #region Sample SQL query
- /*
- * INSERT INTO Domain
- * ([Id]
- * ,[ParentId]
- * ,[HierarchicalIdPath]
- * ,[Name]
- * ,[CreationDate]
- * ,[CreationIdentity]
- * ,[ModificationDate]
- * ,[ModificationIdentity]
- * ,[IsDeleted]
- * ,[DeletionDate]
- * ,[DeletionIdentity])
- * VALUES
- * ('7E571111-7E7D-4FB3-A885-7F253E958933'
- * ,'05CAB111-2D9F-49CF-910A-E009DAF01578'
- * ,(
- * SELECT HierarchicalIdPath FROM Domain
- * WHERE Id = '05CAB111-2D9F-49CF-910A-E009DAF01578'
- * ) + '7E571111-7E7D-4FB3-A885-7F253E958933'
- * ,'NewDOM'
- * ,'11/11/11 11:11'
- * ,'root'
- * ,'11/11/11 11:11'
- * ,'root'
- * ,0
- * ,'11/11/11 11:11'
- * ,'')
- */
- #endregion
- clauses.AddOrReplaceClause(DbExpressionBuilder.SetClause(
- insertCommand.Target.Variable.Property(column),
- DbExpressionBuilder.NewCollection(insertCommand.Target.Expression).Select(
- // insertCommand.Target.Expression.Select(
- exp => insertCommand.Target.Variable
- .Property("HierarchicalIdPath")).Where(
- exp => insertCommand.Target.Variable
- .Property("ParentId")
- .Equal(DbExpression.FromGuid(Guid.Parse("05cab111-2d9f-49cf-910a-e009daf01578")))).Take(DbExpressionBuilder.Constant(1))
- ));
- interceptionContext.Result = new DbInsertCommandTree(
- insertCommand.MetadataWorkspace,
- insertCommand.DataSpace,
- insertCommand.Target,
- clauses.AsReadOnly(),
- null);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement