2017-09-16 15 views
0

在我的應用程序中,用戶可以擁有一個配置文件。使用UserIds和ProfileIds

用戶通過輸入電子郵件和密碼創建一個帳戶。這些信息然後存儲在用戶表中。

在用戶創建帳戶後,他們可以創建一個配置文件:Elf配置文件,Dwarf配置文件和屬於用戶的人員配置文件。

這裏是我的ProfileModel:

public class Profile : IProfile 
    { 
     public Guid ProfileId { get; set; } 
     public Guid UserId { get; set; } 
     public string ElfName{ get; set; } 
     public string DwarfName{ get; set; } 
     public string HumanName{ get; set; } 
    } 

我的問題是:我應該如何處理/整個申請工作的簡檔?如果我只有用戶,每次需要獲取用戶的ID時,我都可以撥打User.Identity.GetUserId()

但是ProfileId怎麼樣?我應該每次使用UserId來獲取ProfileId?每次我想使用配置文件時,是否應該爲ProfileId使用HiddenFor?

在這裏有什麼最佳實踐?你們有什麼建議嗎?

回答

0

對於大多數存儲信息的,我得到了userID,然後使用類似var profile = DbContext.Profiles.Single(profile => profile.UserId == userID)

+0

謝謝您的回答。 :) – Bryan

0

如果用戶和用戶配置一個關係到一個,那麼你應該重構你的用戶配置,使Profile.UserId是主鍵和Forign用戶表上的鍵

public class Profile : IProfile 
    { 
     public Guid UserId { get; set; } 
     public string ElfName{ get; set; } 
     public string DwarfName{ get; set; } 
     public string HumanName{ get; set; } 
    }