Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# EF pattern Repository
Could somebody help me please, I'm not understanding the repository pattern very well!
I have a model whereby I have a Person entity with a one-to-one link with a PersonProfile Entity.
So I have my two entities:
public class person
    public int PersonId {get;set;}
    public string Name {get;set;}
    public int PersonProfileId {get;set;}
    public virtual PersonProfile PersonProfile {get;set;}
public class PersonProfile
    public int PersonProfileId {get;set;}
I have a repository for Person and a service for creating the person.
Now I need to make sure that whenever a Person is create a Personprofile is also created and linked (with blank data in it). The idea being prevent me having to check further down the line that the records exist before I try to update or display them.
But how would be best to do it? Create a personprofile repository and send through a reference when I call the create person service? Do it from my controller page and make sure it's all hooked up before I pass the object to the person create service?
personprofile profile = new person profile();
person person = new person();
person.personprofile = profile;
Or is there a better way I'm not just not understandng?
Thanks in advance.
Posted 16-Apr-12 5:51am
Sastry_kunapuli at 16-Apr-12 14:33pm
Repository pattern is used to save all the actions related to a particular class here person for example.So if you are actually trying to say Person.CreatePerson(),it means you are not creating a new person,but you are telling the system that a new person profile has come in.So i guess the PersonProfile is not different from person.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 Sergey Alexandrovich Kryukov 171
3 Yogesh Kumar Tyagi 165
4 ChauhanAjay 156
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530

Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 16 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100