我正在开发一个 Lightswitch 2012 绿地应用程序。我对 Lightswitch 很陌生,所以我的方法可能完全错误。
我有一个 UserProfile 表,它提供了额外的用户详细信息,并且我计划根据需要使用它来查询用户数据。我想添加一个为当前用户查找适当记录的通用方法。以下代码是内联的,我的一个屏幕需要使用此信息:
UserProfile myProfile;
{
var profiles = this.DataWorkspace.ApplicationData.UserProfiles;
string myDomainId = Application.User.Name;
myProfile = (from profile in profiles.OfType<UserProfile>()
where profile != null && profile.DomainId == myDomainId
select profile).FirstOrDefault<UserProfile>();
if (myProfile == null)
{
myProfile = profiles.AddNew();
myProfile.DomainId = myDomainId;
}
}
现在,这段代码在我的一个屏幕中的一个 onsave 例程中运行。我想将其重构为 GetCurrentUserProfile() 方法以供一般使用。我首先尝试将其放入应用程序中,但出现上下文错误。
放置该方法的正确位置在哪里?