2013-01-11 172 views
1

在我的Lightswitch應用程序中,我必須爲用戶存儲地址和電話號碼等附加信息。這是可能的,如果是這樣,怎麼做?如何存儲其他用戶信息

+1

看到邁克爾的帖子:http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/19/LightSwitch-Creating-a -Relationship-on-current-User-through-SecurityData-UserRegistrations-Table.aspx – danihp

+0

非常感謝這是我的問題的答案 – OlimilOops

+0

好吧,我會將它作爲答案發布。 – danihp

回答

1

您的閱讀之後Creating a Relationship on current User through SecurityData.UserRegistrations Tabl e Richard Waddell的帖子。

本文解釋如何在lightswitch中擴展用戶信息。

Basicaly你應該創建一個模型與username屬性。此屬性綁定到用戶的lightswitch。從邁克爾的帖子:

partial void MyProfiles_Inserting(MyProfile entity) 

    { 

     var reg = (from regs in 
         this.DataWorkspace.SecurityData.UserRegistrations 
        where regs.UserName == entity.UserName 
        select regs).FirstOrDefault(); 

     if (reg == null) 

     { 

      var newUser = this.DataWorkspace.SecurityData 
           .UserRegistrations.AddNew(); 
      newUser.UserName = entity.UserName; 
      newUser.FullName = entity.Name; 
      newUser.Password = "changeme/123"; 
      this.DataWorkspace.SecurityData.SaveChanges(); 

     } 

    } 

要獲取當前用戶配置文件:

 MyProfile profile = (from persons in   
          Application.Current.CreateDataWorkspace() 
            .ApplicationData.MyProfiles 
           where persons.UserName == 
            Application.Current.User.Name 
           select persons).FirstOrDefault();