Yep ok, looks like the double queryable is tripping it up. Only option is to either left join to Offices or do the following: Office mainOffice = Offices.First(); return from pc in _context. CalendarEntries join o in Offices on pc.
LocationId equals o. Id into offices from office in offices.DefaultIfEmpty() select new ScheduleEntry { Id = pc. CalendarId, StartDateTime = pc.
StartDateTime? DateTime. MinValue, EndDateTime = pc.
EndDateTime? DateTime. MinValue, Office = pc.
LocationId == 0? MainOffice : office, } I'm assuming you didn't want to do that due to complaints about making it IEnumerable so you will need to join to the Offices queryable some how to tell EF how to string the queries together. Let x = y or value = value is looking for a constant which I guess makes sense.
Yep ok, looks like the double queryable is tripping it up. Only option is to either left join to Offices or do the following: Office mainOffice = Offices.First(); return from pc in _context. CalendarEntries join o in Offices on pc.
LocationId equals o. Id into offices from office in offices.DefaultIfEmpty() select new ScheduleEntry { Id = pc. CalendarId, StartDateTime = pc.
StartDateTime? DateTime. MinValue, EndDateTime = pc.
EndDateTime? DateTime. MinValue, Office = pc.
LocationId == 0? MainOffice : office, }; I'm assuming you didn't want to do that due to complaints about making it IEnumerable so you will need to join to the Offices queryable some how to tell EF how to string the queries together. Let x = y or value = value is looking for a constant which I guess makes sense.
I get the same "Unable to create a constant value of type ..." exception. – JeffN825 May 29 at 2:34 Looked deeper and edited suggestion. Sorry about sloppiness, but trying to answer my own Q and got caught up in this one :D – Gats May 29 at 2:44 Thanks.
I get the same error doing this...BUT if I get the main office Id upfront: var mainOfficeId = Offices.First(). Id, then use that Id in a second join in the query, it works.... It's not ideal, but it works. – JeffN825 May 29 at 2:45 Ok glad you solved it.
– Gats May 29 at 2:50 Thanks. Just to your point earlier though...not being able to do exactly what you have in your example above: pc. LocationId == 0?
MainOffice : office where office is part of the query and mainOffice is a local variable has nothing to do with the data store or SQL server or anything except the way EF has implemented the projection component of their IQueryProvider. There's no reason your example shouldn't be able to work...but it doesn't. – JeffN825 May 29 at 2:55.
First executes query when expression tree is constructed so it tries passing Office as parameter to your query which cannot be done. One way to replace First is calling this.Offices. Take(1).
That also produces the same "Unable to create a constant value of type" error. Also - First does NOT execute the query when the expression tree is constructed if it's part of a larger expression tree. That is, in the original example I provided, it is created as a MethodCallExpression for the Method First...it is not executed directly at construction time.
– JeffN825 May 29 at 14:17 @Jeff: I just tested First on another query and once I use it in subquery I get an exception: The method 'First' can only be used as a final query operation. Consider using the method 'FirstOrDefault' in this instance instead. So I still think that First cannot be used inside the query but FirstOrDefault can.
– Ladislav Mrnka May 29 at 14:23 Good point!...but that is still a function of the EF provider, not the way expression trees are created. I just tried replacing the First() in my example with FirstOrDefault() and I still do get the same "Unable to create a constant value..." exception... – JeffN825 May 29 at 14:34 I'm still surprised that Take(1) doesn't work - I successfully used it before instead of First. It looks like EF provider doesn't like the way how different result sets are combined in the query because generally your subquery should have to be executed for each record with pc.
LocationId == 0. – Ladislav Mrnka May 29 at 14:43.
Complex TypesFind out how to group properties on your entities into complex types. Associations/RelationshipsLearn how to configure relationships in your model. TPT Inheritance PatternLearn how to implement the Table-per-Type (TPT) inheritance pattern in your model.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.