Contents tagged with linq

  • Repository and Unit of Work for Entity Framework (EF4) for Unit Testing

    Tags: Entity Framework, c#, linq, EF4

    If you are not familiar with the Unit of Work pattern you should firt look at Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10).  It's a great article that demonstrates what the Unit of Work pattern can do.

    Unfortunately, that article uses a different version of Entity Framework.  I am using the default tools that come with Visual Studio and didn't want to modify the project too greatly so for me, the code wasn't usable.  I also wanted to expose the IQueryable interface which as a side effect also simplified my Repository design.

    By using a Repository Pattern you'll find unit testing is now possible and quite easy to write.  This illustration (taken from shows the differences between No Repository and the Repository Pattern.  Notice how there are no Unit Tests in the No Repository section also note the "Alternative Persistence Medium" node (this is where our MemoryRepository comes in).


  • Generic IQueryable Repository for Entity Framework 4 (EF4)

    Tags: c#, linq, Entity Framework, EF4

    Anyone who has tried to create tests with Entity Framework (EF) knows that EF is not very unit test friendly. I needed something simple, reusable and unit testable. this generic repository was the result.

    The goal of this project was high reusability, ease of implementation and to be unit tests friendly.

    There are a lot of Repository Pattern's out there that hide a lot of the underlying functions of your data access layer (in this case LINQ). Well, I really like LINQ to SQL and didn't want to hide any of that. Plus, if you really need encapsulation it should be done in your service layer and not your repository layer.


  • MiniLinq for Script#

    Tags: script#, c#, javascript, linq

    Script# is my new favorite piece of technology. Write JavaScript with C#? Yes please! But since it's (currently) limited to ISO-2 C#, it can feel like you're stuck back in 2004. Using C# 2 means you're missing a lot of things you use daily... like LINQ. I do miss LINQ. So I read about Script# adding a few LINQ like extensions to the array class and decided to work them together into this MiniLinq class, which I am now sharing with you.