Skip to content
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>());
}
}

#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 @@ -72,12 +72,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 @@ -265,6 +265,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.");

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

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