News for hackers. Stuff that matters.
Re:Understanding the .NET ecosystem: The evolution of .NET i... by magicalhippo on Tuesday March 21, 2023 @06:34PM (#35253647)
Well that was my point, either you're writing a lot of code yourself ("assembly"), or you use EF ("Python").

We're not used to something like EF, perhaps it would work for us. But debugging generated queries due to performance issues is something we'd like to avoid. For now the decision was made to not use EF.

Re:Understanding the .NET ecosystem: The evolution of .NET i... by mattmanser on Tuesday March 21, 2023 @06:53PM (#35253871)
You can easily echo them to the console or debug window.

To be honest you should keep all ORM queries fairly simple if you can. Where clauses fine. Inserts, updates, deletes, ORMs save so much code, and so much pain when you add new properties/remove them.

But if a query is more than a few includes or joins you should be handcrafting it with FromSQL() or loading it piecemeal using Load().

And don't even think about using it to make complicated reports, that is not a good idea. Make a stored procedure or view.

And that's especially true if you are using anything other than SQL Server. I've seen abysmal performance myself on MySQL/Maria on moderately complex EF queries. I've not really looked since EF 6, but it used to love making nested selects instead of JOINs, which were fine in SQL Server but terrible performance-wise in MySQL. Postgre I've never used with EF in anger so can't comment.

You can use EF with Hot chocolate to make a GraphQL endpoint really easily, but I'd imagine that's an easy way to saddle yourself with serious performance problems unless you limit the levels it can go. I'd be interested to hear if anyone's using it and how they find it?

Re:Understanding the .NET ecosystem: The evolution of .NET i... by emodendroket on Tuesday March 21, 2023 @08:18PM (#35254827)
What I personally dislike about it is, for the easy stuff, I'm not sure it really saves that much code over a micro-ORM like Dapper, and for the hard stuff, well, everyone's a Linq wizard already so they're tempted to use it, especially if not in the habit of writing much SQL. With today's tools you can even get Intellisense on inlined SQL queries.

Also the lazy-loading and the in-memory provider for tests are both kind of misfeatures.

Re:Understanding the .NET ecosystem: The evolution of .NET i... by bhubert on Tuesday March 21, 2023 @06:58PM (#35253937)
I think you might find Linq2Db[0] to be the right fit for you then, which brands itself on being typesafe SQL in C#.

[0]: https://github.com/linq2db/linq2db

Re:Understanding the .NET ecosystem: The evolution of .NET i... by NicoJuicy on Tuesday March 21, 2023 @07:16PM (#35254152)
EF handles migration and you can re-use the DbConnection and execute plain SQL.

If you don't want to debug difficult queries, then extend it to use Dapper and use the best of both worlds.

Re:Understanding the .NET ecosystem: The evolution of .NET i... by andix on Tuesday March 21, 2023 @07:48PM (#35254524)
You don’t have to use migrations, it’s an optional feature. It works equally well to just generate entities from an existing database, that is migrated/set-up in any other way (as long as the schema is not crazily complex).
Re:Understanding the .NET ecosystem: The evolution of .NET i... by other_herbert on Wednesday March 22, 2023 @12:04AM (#35256684)
Not my project/not affiliate but Evolve is wonderful for handling db migrations
Re:Understanding the .NET ecosystem: The evolution of .NET i... by NicoJuicy on Wednesday March 22, 2023 @01:24AM (#35257157)
Haven't heard of Evolve before, but used DbUp in the past with success too: https://dbup.readthedocs.io/en/latest/
Re:Understanding the .NET ecosystem: The evolution of .NET i... by fabian2k on Tuesday March 21, 2023 @07:32PM (#35254356)
EF Core generates pretty good queries for common cases. I'm not entirely sure about really complex analytical queries, but you might want drop down to SQL for those anyway.

There is one gigantic footgun in EF Core, that is the decision between single query and split query. If you choose single query in the wrong situation you can end up with truly pathological queries. I might blame EF Core here a bit for a dangerous default, but to be honest the other choice would be dangerous in a different way, so there is no obvious good default choice here. This is a part that you need to understand to use this ORM, and fortunately it generates warnings now and kind of forces you to choose the strategy.

The one other aspect that helps to generate good queries with EF Core is to use "Select()" for any case where you want to request fewer columns than available in your tables. I find it quite natural to write queries this way in any case.

Re:Understanding the .NET ecosystem: The evolution of .NET i... by andix on Tuesday March 21, 2023 @07:34PM (#35254377)
You can use EF Core also with plain SQL queries, if you don’t like/trust the query builder. You can also disable change tracking completely, if you prefer to only INSERT/UPDATE directly with SQL statements. You get a lot of awesome features, but nobody forces you to use them.
Re:Understanding the .NET ecosystem: The evolution of .NET i... by magicalhippo on Tuesday March 21, 2023 @07:40PM (#35254450)
Well that sounds a lot better than what my coworkers told me. Will definitely check out EF Core.
Re:Understanding the .NET ecosystem: The evolution of .NET i... by WorldMaker on Wednesday March 22, 2023 @02:10PM (#35264917)
Yeah, EF's Interpolated Execute methods are a massive step up over raw ADO.NET ("assembly"), even if you don't use most of the other modeling tools and context tracking.

The Interpolated family of methods take nice, clean string interpolation like $"Select * from Table where Id = {Id}" and make sure that is properly parametric SQL queries (ie, avoiding things like SQL injection attacks).

It's a killer feature and I have some idea why it lives in the EF side of the house rather than being generally applied across all of ADO.NET, but it should still probably be a more reusable library of its own beyond just EF.