diff --git a/ChangeLog/7.1.2_dev.txt b/ChangeLog/7.1.2_dev.txt
index e69de29bb2..78b15d4fc6 100644
--- a/ChangeLog/7.1.2_dev.txt
+++ b/ChangeLog/7.1.2_dev.txt
@@ -0,0 +1 @@
+[main] Addressed issue when cycles in Entity dependency graph were not detected
\ No newline at end of file
diff --git a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs
index 0a30a6b5e0..282ee03543 100644
--- a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs
+++ b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs
@@ -9,7 +9,9 @@
using Xtensive.Collections;
using System.Linq;
using Xtensive.Core;
-
+using DotNetNotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;
+using JBNotNullAttribute = JetBrains.Annotations.NotNullAttribute;
+using JBCanBeNullAttribute = JetBrains.Annotations.CanBeNullAttribute;
namespace Xtensive.Sorting
{
@@ -29,6 +31,7 @@ public static class TopologicalSorter
/// Sorting result, if there were no loops;
/// otherwise, .
///
+ [JBCanBeNull]
public static IEnumerable Sort(IEnumerable items, Predicate connector) =>
Sort(items, connector, out List> loops);
@@ -43,6 +46,7 @@ public static IEnumerable Sort(IEnumerable item
/// Sorting result, if there were no loops;
/// otherwise, .
///
+ [JBCanBeNull]
public static IReadOnlyList SortToList(IEnumerable items, Predicate connector) =>
SortToList(items, connector, out List> loops);
@@ -59,6 +63,7 @@ public static IReadOnlyList SortToList(IEnumerable.
/// In this case will contain only the loop edges.
///
+ [JBCanBeNull]
public static IEnumerable Sort(
IEnumerable items,
Predicate connector,
@@ -83,6 +88,7 @@ public static IEnumerable Sort(
/// otherwise, .
/// In this case will contain only the loop edges.
///
+ [JBCanBeNull]
public static IReadOnlyList SortToList(
IEnumerable items,
Predicate connector,
@@ -105,6 +111,8 @@ public static IReadOnlyList SortToList(
///
/// Sorting result
///
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IEnumerable Sort(
IEnumerable items,
Predicate connector,
@@ -121,6 +129,8 @@ public static IEnumerable Sort(
///
/// Sorting result
///
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IReadOnlyList SortToList(
IEnumerable items,
Predicate connector,
@@ -138,6 +148,8 @@ public static IReadOnlyList SortToList(
///
/// Sorting result
///
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IEnumerable Sort(
IEnumerable items,
Predicate connector,
@@ -161,6 +173,8 @@ public static IEnumerable Sort(
///
/// Sorting result
///
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IReadOnlyList SortToList(
IEnumerable items,
Predicate connector,
@@ -181,9 +195,16 @@ public static IReadOnlyList SortToList(
/// Sorting result, if there were no loops;
/// otherwise, .
/// In this case will contain only the loop edges.
+ [JBCanBeNull]
public static IEnumerable Sort(
List> nodes,
- out List> loops) => SortInternal(nodes, out loops).sorted ?? Array.Empty();
+ out List> loops)
+ {
+ var (sorted, count) = SortInternal(nodes, out loops) /* ?? Array.Empty()*/;
+ return (sorted is not null && count == 0)
+ ? Array.Empty()
+ : sorted;
+ }
///
/// Sorts the specified oriented graph of the nodes in their topological order
@@ -194,14 +215,17 @@ public static IEnumerable Sort(
/// Sorting result, if there were no loops;
/// otherwise, .
/// In this case will contain only the loop edges.
+ [JBCanBeNull]
public static IReadOnlyList SortToList(
List> nodes,
out List> loops)
{
var (sorted, count) = SortInternal(nodes, out loops);
- return (sorted is null || count == 0)
- ? Array.Empty()
- : sorted.ToArray(count);
+ return (sorted is null)
+ ? null
+ : count == 0
+ ? Array.Empty()
+ : sorted.ToArray(count);
}
///
@@ -211,6 +235,8 @@ public static IReadOnlyList SortToList(
/// The nodes.
/// Edges removed to make graph non-cyclic.
/// Sorting result.
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IEnumerable Sort(
IEnumerable> nodes,
out List> removedEdges) =>
@@ -223,6 +249,8 @@ public static IEnumerable Sort(
/// The nodes.
/// Edges removed to make graph non-cyclic.
/// Sorting result.
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IReadOnlyList SortToList(
IEnumerable> nodes,
out List> removedEdges) =>
@@ -236,6 +264,8 @@ public static IReadOnlyList SortToList(
/// Edges removed to make graph non-cyclic.
/// If removes whole node in the case of loop, otherwise removes only one edge.
/// Sorting result.
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IEnumerable Sort(
IEnumerable> nodes,
out List> removedEdges,
@@ -250,6 +280,8 @@ public static IEnumerable Sort(
/// Edges removed to make graph non-cyclic.
/// If removes whole node in the case of loop, otherwise removes only one edge.
/// Sorting result.
+ [return: DotNetNotNull]
+ [JBNotNull]
public static IReadOnlyList SortToList(
IEnumerable> nodes,
out List> removedEdges,