Click here to Skip to main content
15,888,803 members
Home / Discussions / C#
   

C#

 
AnswerRe: Convert JSON Array Objects Into Dotnet Objects Pin
Midi_Mick14-Sep-16 4:24
professionalMidi_Mick14-Sep-16 4:24 
AnswerRe: Convert JSON Array Objects Into Dotnet Objects Pin
Midi_Mick14-Sep-16 4:32
professionalMidi_Mick14-Sep-16 4:32 
GeneralRe: Convert JSON Array Objects Into Dotnet Objects Pin
MadDashCoder14-Sep-16 5:25
MadDashCoder14-Sep-16 5:25 
QuestionEF code first telling me to do the migration for db object which is already is in db Pin
Tridip Bhattacharjee12-Sep-16 22:53
professionalTridip Bhattacharjee12-Sep-16 22:53 
GeneralRe: EF code first telling me to do the migration for db object which is already is in db Pin
Nathan Minier13-Sep-16 1:37
professionalNathan Minier13-Sep-16 1:37 
GeneralRe: EF code first telling me to do the migration for db object which is already is in db Pin
Richard Deeming13-Sep-16 2:27
mveRichard Deeming13-Sep-16 2:27 
GeneralRe: EF code first telling me to do the migration for db object which is already is in db Pin
Tridip Bhattacharjee13-Sep-16 2:32
professionalTridip Bhattacharjee13-Sep-16 2:32 
GeneralRe: EF code first telling me to do the migration for db object which is already is in db Pin
Nathan Minier13-Sep-16 2:46
professionalNathan Minier13-Sep-16 2:46 
Well, Mr Deeming's answer might suit you better, but for a quick and dirty example:
C#
public class User //persistence model
{
   public string UserName {get;set;}
   public string PasswordHash {get;set;}
   public DateTime Created { get; set; }
   public int RoleId { get; set}

   [Foreginkey("Role")
   public virtual Role Role { get; set;}
}

public class Role // persistence model
{
   public int Id { get; set; }
   public string Title { get; set; }
   public int GroupId {get; set; }

   [ForeignKey("GroupId")]
   public virtual Group AssignedGroup {get; set;} //not gonna bother defining past here

   public virtual ICollection<User> Users { get; set; }
}

public class UserViewModel //view model with specific projections
{
   public string UserName {get;set;}
   public string Role {get; set;}
   public DateTime Created { get; set; } 

   public UserViewModel(){}
   public UserViewModel(User user)
   {
      UserName = user.UserName;
      Role = user.Role.Title;
      Created = user.Created;
   }
}

public class UserController: ApiController //WebAPI2 sample for SNGs
{
   ...
   public IEnumerable<UserViewModel> GetUsers()
   {
      return myDbContext.Users.Select(x => new UserViewModel(x)).ToArray(); //Database call is made here
   }
}
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli

GeneralRe: EF code first telling me to do the migration for db object which is already is in db Pin
Tridip Bhattacharjee13-Sep-16 21:45
professionalTridip Bhattacharjee13-Sep-16 21:45 
AnswerRe: EF code first telling me to do the migration for db object which is already is in db Pin
Richard Deeming13-Sep-16 2:32
mveRichard Deeming13-Sep-16 2:32 
QuestionResource file in c# (.resx) Pin
Harpreet05Kaur12-Sep-16 22:03
Harpreet05Kaur12-Sep-16 22:03 
AnswerRe: Resource file in c# (.resx) Pin
OriginalGriff12-Sep-16 22:21
mveOriginalGriff12-Sep-16 22:21 
QuestionWindows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 10:53
professionalKevin Marois12-Sep-16 10:53 
AnswerRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 10:58
mveDave Kreskowiak12-Sep-16 10:58 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:00
professionalKevin Marois12-Sep-16 11:00 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 11:38
mveDave Kreskowiak12-Sep-16 11:38 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:39
professionalKevin Marois12-Sep-16 11:39 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 11:40
mveDave Kreskowiak12-Sep-16 11:40 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:42
professionalKevin Marois12-Sep-16 11:42 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 11:48
mveDave Kreskowiak12-Sep-16 11:48 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:49
professionalKevin Marois12-Sep-16 11:49 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 11:53
mveDave Kreskowiak12-Sep-16 11:53 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:56
professionalKevin Marois12-Sep-16 11:56 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 11:57
mveDave Kreskowiak12-Sep-16 11:57 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Kevin Marois12-Sep-16 11:58
professionalKevin Marois12-Sep-16 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.