Saturday, October 26, 2013
braindump of making EF (Entity Framework) Suck Less as hosted by Tim Rayburn at Pablo's Fiesta in room 105
Tim askes if anyone is doing test driven with EF. Tim has made expansions on top of EF to make it more testable. Highway Framework is a framework ontop of Entity Framework that makes it suck less. Tim every ORM that has every existed is drying to map a row in a table to an object that is a hodgepodge of behavior and state and this is comparing apples to oranges. There are some common things to do in an ORM - create read update and delete. Do separation between repo and unit of work. Tim prefers to call "code first" "code centric" ---he feels that in C# he will want to use C# as the primary point of definition and not a SQL schema. Unit testing is important to Tim and EF falls down in this regard he feels. He feels testability really kills things. EF6 just dropped. The definition of a DbContext shows that it will return a DbSet of T which will be hard to mock. Tim believes one of the greatest evils in recent years is Queryable. Everyone knows not to bury SQL strings in code, but somehow Queryable is OK? Not so much. Queryable is not read only it can be modified at the ORM itself. Having get person by Id in your code base based on Queryable you will have code sprinkled about that will require multiple changeups to fix. Tim is using Code Rush in his presentation. Visual Studio 2013 will have the grey word reference appearing over method signatures which you may mouse over to see references! public ICollection<Tasks> Tasks { get; set; } is an example of specifying a collection from a parent in the code first core classes. Database.SetInitializer(new DropCreateDatabaseAlways<... is yet more EF code. DataContext is a common abstraction over working with different underlying types of data. IDataContext implements IDisposable. IEventManager is something for intercepting transactions for AOP stuff. Tim has way to hand stuff to IDataContext for mocking and let IQueryable hand it back when chained onto it. Tim is coding in front of his audience and making Queryable stuff. All closures are passed by reference in C#. I can't follow the talk. Either it's late in the day and I'm tired or it's just really deep and complicated. I'm not sure. Tim doesn't remember how to insert into an row with one auto incrementing column and no other columns. He is doing some magic to downcast IQueryable to IEnumerable so that where clauses off happen in memory. He has a way to pop off the query behind an IQueryable to a string so that you may test it. I'm starting to space out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment