Skip to content

Throw for DML on filter #2020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/NHibernate.Test/Async/LinqBulkManipulation/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,18 @@ public async Task DeleteSyntaxWithCompositeIdAsync()
}
}

[Test]
public async Task DeleteOnFilterThrowsAsync()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var a = await (s.Query<SimpleEntityWithAssociation>().Take(1).SingleOrDefaultAsync());
var query = a.AssociatedEntities.AsQueryable();
Assert.That(() => query.Delete(), Throws.InstanceOf<NotSupportedException>());
Copy link
Member Author

@bahusoid bahusoid Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maca88 I've just noticed that async versions of DML extension methods are not used at all in async tests. Is it Async Generator bug?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's a bug and I've created an issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Published a new release 0.13.2 that has the bug fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should upgrade the async generator on 5.2x (and even less on previous branches). So we will have to take care of regenerating async files as part of the merge to master I think, in order to take into account the fix now available in master.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thoughts

}
}

#endregion
}
}
}
14 changes: 13 additions & 1 deletion src/NHibernate.Test/LinqBulkManipulation/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,18 @@ public void DeleteOnProjectionThrows()
}
}

[Test]
public void DeleteOnFilterThrows()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var a = s.Query<SimpleEntityWithAssociation>().Take(1).SingleOrDefault();
var query = a.AssociatedEntities.AsQueryable();
Assert.That(() => query.Delete(), Throws.InstanceOf<NotSupportedException>());
}
}

#endregion
}
}
}
3 changes: 3 additions & 0 deletions src/NHibernate/Async/Linq/DefaultQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ protected virtual Task<object> ExecuteQueryAsync(NhLinqExpression nhLinqExpressi

public Task<int> ExecuteDmlAsync<T>(QueryMode queryMode, Expression expression, CancellationToken cancellationToken)
{
if (Collection != null)
throw new NotSupportedException("DML operations are not supported for filters.");
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<int>(cancellationToken);
}
try
{

var nhLinqExpression = new NhLinqDmlExpression<T>(queryMode, expression, Session.Factory);

var query = Session.CreateQuery(nhLinqExpression);
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate/Linq/DefaultQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public virtual void SetResultTransformerAndAdditionalCriteria(IQuery query, NhLi

public int ExecuteDml<T>(QueryMode queryMode, Expression expression)
{
if (Collection != null)
throw new NotSupportedException("DML operations are not supported for filters.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be InvalidOperationException. However, I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As potentially it could be implemented I think NotSupported/NotImplemented exceptions are more appropriate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotSupported is fine


var nhLinqExpression = new NhLinqDmlExpression<T>(queryMode, expression, Session.Factory);

var query = Session.CreateQuery(nhLinqExpression);
Expand Down