Skip to content

Commit d5ade79

Browse files
authored
Null check in GenerateExpandQueryStringInternal (#2795)
1 parent 8c03a90 commit d5ade79

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/Microsoft.AspNet.OData.Shared/Query/ExpandQueryBuilder.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,33 @@ public virtual string GenerateExpandQueryParameter(object value, IEdmModel model
4040

4141
private string GenerateExpandQueryStringInternal(object value, IEdmModel model, bool isNestedExpand)
4242
{
43+
string expandString = "";
44+
45+
if (value == null || model == null)
46+
{
47+
return expandString;
48+
}
49+
4350
Type type = value.GetType();
4451
bool isCollection = TypeHelper.IsCollection(type, out Type elementType);
4552
IEnumerable collection = null;
53+
4654
if (isCollection)
4755
{
4856
type = elementType;
4957
collection = value as IEnumerable;
5058
}
5159

5260
string edmFullName = type.EdmFullName();
53-
IEdmSchemaType schemaType = model.FindType(edmFullName);
54-
IEdmStructuredType edmStructuredType = schemaType as IEdmStructuredType;
61+
62+
IEdmStructuredType edmStructuredType = model.FindType(edmFullName) as IEdmStructuredType;
63+
64+
if (edmStructuredType == null)
65+
{
66+
return expandString;
67+
}
5568

5669
IEnumerable<IEdmNavigationProperty> navigationProperties = edmStructuredType.NavigationProperties();
57-
string expandString = "";
5870

5971
int count = 0;
6072

0 commit comments

Comments
 (0)