3 ms·
Stored procedures? No. It makes it much more difficult to keep the code and the stored procedures in sync. Also unit testing is more difficult and slower. With
by scarface74 8y ago
Stored procedures? No. It makes it much more difficult to keep the code and the stored procedures in sync. Also unit testing is more difficult and slower. With linq, you can unit test your queries without ever touching a database by mocking out your context and using Lists (https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113).aspx https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113)....)
Also, it’s a lot easier and less error prone to compose dynamic queries with Linq - ie keep chaining Where clauses and OrderBy’s based on a condition.
You can also do things like create methods that take predicates.
CustomerRepo.Find( c=>c.age > 65)
And define the Find method.
List<Customer> Find(Expression<Func<Customer,T>> predicate).
I’ve even had one project where the backing store could either be SQL Server or Mongo. We were able to use the same interface with methods like the Find method above
and the repos translated the predicates appropriately.
- scarface74 8y agoJust because I don't want bad syntax to live on for eternity on HN... List<Customer> Find(Expression<Func<Customer,T>> predicate) Should be List<Customer> Find(Expression<Func<Customer,bool>> predicate)
- qubax 8y ago> Also, it’s a lot easier and less error prone to compose dynamic queries with Linq That's the general assumption of people not familiar with SQL, RDBMs and full stack architecture. One of my issues is that ORMs and LINQ have become crutches. Also, you are ignoring the major problem of security and auditing. If you are working on a local toy project, then sure, you can just do whatever you want. But if it is an enterprise project with real security concerns, the idea of giving read/write access to web server accounts is amateur hour. Trust me, I've seen it with my own eyes. People who spend 2 days reading "Learn web dev in 21 days" and "Learn SQL in 21 days" and putting today something akin to "Hello world" projects because their managers didn't know any better. > - ie keep chaining Where clauses and OrderBy’s based on a condition. You can use LINQ, chaining, lazy evaluation and all that on data/Enumerables/sequences retrieved from a stored procedure. But hey, what do I know.