sql server - Handle the same nullable Entity relation at both SQL and C# -


i project entity, , non-nullable property of 1 - 0..1 related entity, new result. it's common need, similar how select non nullables nullable relation in entity framework

no problem, say, right? in case, coalesce value non-nullable fallback.

appointment => new clientappointmentviewmodel {     id = appointment.id,     phone = appointment.phone.normalized ?? appointment.client.phone.normalized, 

an appointment may not have one-time phone number associated it, instead we'll call client's profile phone number. yay!

however, question is, can write shared code run against sql data , in-memory entities?

this executes fine as store expression. when retrieve list of clientappointmentviewmodel directly database, well. entire sql query relationship generated appointment.phone.normalized interpreted 1 nullable value, , coalesce works fine.

however, use on single in-memory entity instance. suppose i've inserted appointment , returning single resulting clientappointmentviewmodel confirmation in ui. in case, appointment in-memory, transformation runs c# , returns null reference error: appointment.phone null.

i go other way, , extend entity property (e.g. fallbackphone) executes conditional logic. run fine on in-memory instance, fail translate store expression. won't run @ against sql.

how can write logic once, represent both cases?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -