如何存储其他用户信息

时间:2013-01-11 13:49:39

标签: visual-studio-lightswitch

在我的Lightswitch应用程序中,我必须为用户存储地址和电话号码等附加信息。这是可能的,如果是这样,怎么做?

1 个答案:

答案 0 :(得分:1)

您阅读Creating a Relationship on current User through SecurityData.UserRegistrations Tabl Richard Waddell的帖子。

本文介绍如何在lightswitch中扩展用户信息。

基本上你应该创建一个username属性的模型。此属性绑定到lightswitch表单用户。来自Michael的帖子:

    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();