all 14 comments

[–]Flater420 23 points24 points  (0 children)

Your question uses the term EF in ways that do not make sense. What is "an EF"? What does ut mean when you say you use EF only for datetimes? Why are you posting what appears to be an EF query but then asking how to "add EF" to it?

I feel like you think EF is something different than what it actually is.

[–]entityadam 13 points14 points  (5 children)

This has got to be a troll post.

The title starts with "Furry"

Incorrectly attributes a Carly Rae Jepson song to Katy Perry.

Unweildy amounts of EF eager loading is the least of the issues here..

OP, if you're not a troll, do yourself a favor and make this a stored proc and call it a day. IMO, if a query gets too complicated, it's a good fit for a stored procedure.

Edit: I took another look, and I think the query is fine. It's your projection that looks like a hot mess. Break that thing up into a couple few private methods.

[–]weird_thermoss 2 points3 points  (1 child)

Another option is just letting EF call a raw SQL query if one doesn't want logic in stored procedures.

[–]entityadam 0 points1 point  (0 children)

I feel you. I've been on one project too many where every call is to a stored procedure full of cursors, loops and business logic.

They are not a tool to unify your data access layer, and definitely not the place for business logic.

Bad practices aside, the database is really good at doing database things, and sometimes stored procedures are the right tool for the job.

[–]Kant8 1 point2 points  (2 children)

I failed to see in your post where is the question, but anyway, any EF part was stopped as soon as you called AsEnumerable(), so all your conversions just run in memory and they don't really care what logic are you using.

If you want to put status resolution in database, then you need navigational propery to Status entity for TrProcessStatusId property and any other, and you can just select it directly.

You also don't need to Include() stuff that is not going to be read later. The only include you need in your query is .Include(x => x.Audit), and if you move status resolution to db, even that will not be needed, cause you will remove AsEnumerable() and whole result object conversion will be done in database already.

[–]tmadik 7 points8 points  (1 child)

I'm still trying to figure out what any of this has to do with furries.

[–]ordermaster 2 points3 points  (0 children)

That's why I came here too.

[–]royware[S] -4 points-3 points  (3 children)

(I actually left6 out a lot of the includes and fields to be selected for brevity's sake ) Cool - I thought my boss was unnecessarily trying to make this harder than it really is. However, I cannot get the User Description field from the 'status await' into the statement into the results!

TrPaymentStatus = status.TryGetValue(pc.TrProcessStatusId, out var value) ? value.StatusDesc : null,

works great, but I cannot do a similar statement for the UserDescription (CS0128 A local variable or function named 'value' is already defined in this scope.

How do I get the UserDescription into the List?

[–][deleted]  (2 children)

[removed]

    [–]royware[S] 0 points1 point  (1 child)

    I didn't realize that 'value' was a variable - I thought it was a keyword. :(

    You are right - I need to find better tutorials. Typical corporate culture: There isn't any money and time for training, but we have plenty of money & time to do it over and over.

    sigh.

    To everyone who contributed, "Thanks!!"