You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From developer perspective it's a perfectly valid code, it compiles, however it throws
System.InvalidCastException: Unable to cast object of type 'System.Linq.EmptyPartition`1[PnP.Core.Model.SharePoint.IView]' to type 'PnP.Core.Model.SharePoint.IView'.
at this line as a result of this. View does not implement IQueryableDataModel, as a result a new Enumerable.Empty<TModel>(); is returned, but the cast fails later on.
I used the View object as an example, we might see the similar issues for other objects as well. The problem is, that we actually don't know what should be the return type. If I use FirstOrDefault, then the return type should be default(TModel), if ToList, then IEnumerable<TModel> etc. Even if we return a valid type, it still might be confusing for a library consumer why it doesn't return value? (I know, that there is a view called `All Documents), but the library return null.
Would it be more natural to just throw an exception in this case? I.e. if a class does not implement IQueryableDataModel, then here:
- return Enumerable.Empty<TModel>();+ throw new Exception($"LINQ queries are not supported for {typeof(TModel).Name} type.");
The text was updated successfully, but these errors were encountered:
Thanks for reporting this @s-KaiNet. The fact that some models that are populated via REST and having their LinqGet property set do not have the IQueryableDataModel interface set is wrong. I'll fix those.
I also do like the idea of throwing an exception instead of returning an empty collection, think this way things will be better for the developer as there's clarity on why things do not work.
Category
Describe the bug
When I try to get a listview by its title, I got an exception.
Steps to reproduce
The code is fairly simple:
From developer perspective it's a perfectly valid code, it compiles, however it throws
at this line as a result of this.
View
does not implementIQueryableDataModel
, as a result a newEnumerable.Empty<TModel>();
is returned, but the cast fails later on.I used the
View
object as an example, we might see the similar issues for other objects as well. The problem is, that we actually don't know what should be the return type. If I useFirstOrDefault
, then the return type should bedefault(TModel)
, ifToList
, thenIEnumerable<TModel>
etc. Even if we return a valid type, it still might be confusing for a library consumer why it doesn't return value? (I know, that there is a view called `All Documents), but the library return null.Would it be more natural to just throw an exception in this case? I.e. if a class does not implement
IQueryableDataModel
, then here:The text was updated successfully, but these errors were encountered: