Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 1bd3535

Browse files
committed
Made recursion of complex type an opt-in feature
1 parent 47b01da commit 1bd3535

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Community.Data.OData.Linq/Builder/ODataModelBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public virtual IEnumerable<OperationConfiguration> Operations
140140
get { return this._operations; }
141141
}
142142

143+
/// <summary>
144+
/// Gets/Sets the ability to allow recursion of complex types
145+
/// </summary>
146+
public bool AllowRecursiveLoopOfComplexTypes { get; set; }
147+
143148
/// <summary>
144149
/// Gets or sets the navigation property binding options.
145150
/// </summary>

Community.Data.OData.Linq/Builder/StructuralTypeConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo prop
383383
throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, this.ClrType.FullName);
384384
}
385385

386-
if (propertyInfo.PropertyType == this.ClrType)
386+
if (propertyInfo.PropertyType == this.ClrType && ModelBuilder?.AllowRecursiveLoopOfComplexTypes != true)
387387
{
388-
//throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, this.ClrType.FullName, propertyInfo.Name);
388+
throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, this.ClrType.FullName, propertyInfo.Name);
389389
}
390390

391391
this.ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo);

Community.Data.OData.Linq/ODataSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static void SetInitializer(Action<ODataSettings> initializer)
4949

5050
public bool EnableCaseInsensitive { get; set; } = true;
5151

52+
public bool AllowRecursiveLoopOfComplexTypes { get; set; } = false;
53+
5254
public DefaultQuerySettings DefaultQuerySettings { get; } =
5355
new DefaultQuerySettings
5456
{

Community.Data.OData.Linq/OdataLinqExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ public static ODataQuery<T> OData<T>(this IQueryable<T> query, Action<ODataSetti
5454
{
5555
if (query == null) throw new ArgumentNullException(nameof(query));
5656

57+
ODataSettings settings = new ODataSettings();
58+
configuration?.Invoke(settings);
59+
5760
if (edmModel == null)
5861
{
5962
edmModel = Models.GetOrAdd(typeof(T), t =>
6063
{
6164
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
6265
builder.AddEntityType(t);
63-
builder.AddEntitySet(t.Name, new EntityTypeConfiguration(new ODataModelBuilder(), t));
66+
builder.AddEntitySet(t.Name, new EntityTypeConfiguration(new ODataModelBuilder { AllowRecursiveLoopOfComplexTypes = settings.AllowRecursiveLoopOfComplexTypes }, t));
6467
return builder.GetEdmModel();
6568
});
6669
}
@@ -72,9 +75,6 @@ public static ODataQuery<T> OData<T>(this IQueryable<T> query, Action<ODataSetti
7275
}
7376
}
7477

75-
ODataSettings settings = new ODataSettings();
76-
configuration?.Invoke(settings);
77-
7878
int settingsHash = HashCode.Combine(
7979
settings.QuerySettings,
8080
settings.DefaultQuerySettings,

0 commit comments

Comments
 (0)