Updating net framework

28 Jan

In fact, I won’t touch the repository interfaces at all. Actually, it wasn't there on my code but while I was writing the post, I wanted to add there. As for your suggestion, yes it can be dropped and even as you suggested, we can have one method which accepts an optional paramater that is type of x. With a 2nd method you'd end up needing to basically duplicate the above mock but forward the where predicate to Foo Repository. comment by scott gu near the bottom) Thanks though... I want to be able to make model classes any ole way I want and persist them with EF (with some generic implementation if possible) or any other persistence model/device be it NHibernate, XML or simple Db. @Chris IGeneric Repository is not specific to the EF.What I did here first is to create an abstract class which implements IGeneric Reposity abstract class to access an instance of Db Context. IGeneric Repository would be defined in your Model somewhere.

If the entity is not in the context then a query will be executed and evaluated against the data in the data source, and null is returned if the entity is not found in the context or in the data source.

Everything was ok until a few days ago I had to do a complex linq query requiring doing an union on two Db Sets (coming from two distinct repositories).

I was thrown an ugly exception letting me know that no union was possible because unions needs to be done in the same Db Context (seems logical).

A better approach but still sucks I created a generic interface which saves me a lot of keystrokes. Where I implement these repository interfaces to my concrete classes, I still need to go over all the methods and create them individually. So it leads me to a final solution which is the best one I can come up with so far. UPDATE: Here is the next post: How to Work With Generic Repositories on ASP. But I missed the Find By with a predicate function - I'll have to start using that. The one of the main reason I did the blog post is to get feedback like yours. it may be my lack of experience in the EF, but i would assume you would need a way to dispose automagically... I may have answered my own question with more research. I actually implemented it on my github repo: https://github.com/tugberkugurlu/Generic Repo Web App See the commit: https://github.com/tugberkugurlu/Generic Repo Web App/commit/4a02be1ac1899a476c5f220e042dbbb65546e3cd so here's my beef and I can't seem how to navigate this.

Best approach The generic interface I have created is still legitimate and usable here. NET MVC and Unit Testing Them By Mocking @Chris Marisic Good catch. As Queryable()); Nothing like being able to mock a database with a list. Kinda lame to mock the same thing twice but only adding a . One thing I'd suggest is to make the Context property in Generic Repository protected so that only the child repositories can get at it otherwise you defeat the object of encapsulating the Db Context. I guess it doesnt need to be explicitly called since the context doesnt hold open the connectiion... Even when you use POCOs you're still coupled to some EF responsibilities.