Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Unassigned: Projection and $expand results in The argument to DbIsNullExpression must refer to a primitive, enumeration or reference type. [1473]

$
0
0
When exposing an OData service with a 'projected' DTO model, $expand on a To-One relationship throws a "The argument to DbIsNullExpression must refer to a primitive, enumeration or reference type." exception.

Also, see the below links for other examples of almost identical situations:
http://stackoverflow.com/questions/19323545/odata-expand-dtos-and-entity-framework
http://stackoverflow.com/questions/19662681/webapi-odata-expand-not-serializing-as-expected

In my case below, I have a User entity which has a 0..* relationship to Jobs. Job has a 0..1 relationship to User.

Accessing /Users?$expand=Jobs works just fine. However, accessing /Jobs?$expand=User throws the exception.

Controller method is very simple:

public IQueryable<JobDTO> GetJobs() {
return db.Jobs.ToServiceModel(db);
}

ToServiceModel() is a simple projection:

public static IQueryable<Job> ToServiceModel(this IQueryable<JobDataModel> query) {
return query.Select(job => new Job {
Id = job.Id,
Name = job.Name,
Status = job.Status,
TimeCreated = job.TimeCreated,
User = new User {} // simplified for the example here, actual implementation was projecting job.User
});
}

While doing some debugging, I changed the controller implementation slightly to apply ODataQueryOptions manually so I can see the resulting IQueryable expression:

value(System.Data.Entity.Core.Objects.ObjectQuery`1[DataAccess.Model.Job]).MergeAs(AppendOnly).Select(job => new Job() {Id = job.Id, Name = job.Name, Status = job.Status, TimeCreated = job.TimeCreated, User = new User() {}}).Select(Param_0 => new SelectAllAndExpand`1() {ModelID = "6cf43631-e208-4982-b795-33a7c6aeed97", Instance = Param_0, Container = new SingleExpandedProperty`1() {Name = "User", Value = new SelectAll`1() {ModelID = "6cf43631-e208-4982-b795-33a7c6aeed97", Instance = Param_0.User}, IsNull = (Param_0.User == null)}})
Comments: I ended up writing this solution in the meantime: http://beyondtheduck.com/projecting-and-expand-possible-at-last-kinda/

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>