我正在开发Lightswitch 2012绿地应用程序。我对Lightswitch非常陌生,所以我的方法可能完全错误。在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()方法。我第一次尝试把它放在应用程序中,但我得到了上下文错误。
哪里可以放置该方法?
链接已死亡。也许这是一个适当的更新[MSDN论坛:在哪里放置自定义代码是全球所有lightswitch entites?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/dd9e3328-66ab-4702 -80a3-b0bacee56e70/where-to-place-custom-code-that-is-global-to-all-lightswitch-entites?forum = lightswitch) – spikey 2014-10-23 08:25:53
感谢spikey。我已经从使用DNN转移到我的博客。我正在将帖子逐渐移至www.yannduran.com/blog,但该帖子还没有发布。您提供的链接不适用于当前的LightSwitch开发,因为不再有Common项目,并且所有客户端代码都是JavaScript(尽管您仍然使用C#/ VB作为服务器端代码)。 – 2014-10-23 08:31:18