Linq to sql Repository pattern , Some doubts
Posted
by MindlessProgrammer
on Stack Overflow
See other posts from Stack Overflow
or by MindlessProgrammer
Published on 2010-04-09T19:37:56Z
Indexed on
2010/04/09
20:33 UTC
Read the original article
Hit count: 302
I am using repository pattern with linq to sql, I am using a repository class per table. I want to know , am i doing at good/standard way,
ContactRepository
Contact GetByID()
Contact GetAll()
COntactTagRepository
List<ContactTag> Get(long contactID)
List<ContactTag> GetAll()
List<ContactTagDetail> GetAllDetails()
class ContactTagDetail
{
public Contact Contact {get;set;}
public ContactTag COntactTag {get;set;}
}
When i need a contact i call method in contactrepository, same for contacttag
but when i need contact and tags together i call GetDetais() in ContactTag repository its not returning the COntactTag entity generated by the orm insted its returning ContactTagDetail entity conatining both COntact and COntactTag generated by the orm, i know i can simple call GetAll in COntactTag repository and can access Contact.ContactTag but as its linq to sql it will there is no option to Deferred Load in query level, so whenever i need a entity with a related entity i create a projection class
Another doubt is where i really need to right the method i can do it in both contact & ContactTag repostitory like In contact repository GetALlWithTags() or something but i am doing it in in COntactTag repository
Whats your suggestions ?
© Stack Overflow or respective owner