What's up!

Pyaarey Allah!

Saturday, August 6, 2011

My style of Generic repository with EF4.1(x=anything First)


/* People even in Microsoft are breaking rules of 
Repository Pattern
by making code first generic repository.
If you wanna break rules then
nothing is better than my repository pattern 
:) No pain and lots of gain.
No need to make a lots of concrete classes like 
public class UserRepository : Repository<User>
Simple make one Generic Repository 
and start rocking.
Criticism is welcomed, warmly. */ 
class Program
        static void Main(string[] args)
            var ctx = new GiobyContextContainer();
            GenericRepository r = new GenericRepository(ctx);
            User user = r.Find<User>(8);
            Folder f = r.Find<Folder>(1);
            AccessOnFolder aof = new AccessOnFolder
                AllowedUserID = user.UserID,
                FolderID = f.FolderID,
                ReadPermission = true,
                WritePermission = true