c# - 如何在其他类的 lightswitch 中访问数据库?

标签 c# switch-statement visual-studio-lightswitch ls light


我只是不知道如何解释清楚。所以我创建了一个我所做的简单图像模式。
我的问题是,我怎样才能在 LS 的其他类(class)访问我的数据库?
我一直在网上搜索,但没有找到任何解决方案。我希望我能在这里找到它。
谢谢!。 enter image description here


任何建议都已受到赞赏。

最佳答案

感谢 Bryan 的回答,但我在这里找到了问题的答案 Richard Waddell


以下是我为实现目标所做的工作。

  1. 将您的 LS 项目切换到文件 View
  2. 转到“Common”项目,在“UserCode”文件夹下,创建一个类(例如Authenticate.cs)并放入此代码。

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public class Authenticate
    {
        public static adminuser GetCurrentUser()
        {
            adminuser userFound = (from useritem in 
            Application.Current.CreateDataWorkspace().basecampcoreData.adminusers
            where useritem.LoginID == Application.Current.User.Name
            select useritem).SingleOrDefault();

            if (userFound != null)
                return userFound;
            else
                return null;
        }
    }
}

然后您现在可以在项目的任何位置调用 Authenticate.GetCurrentUser()
谢谢!

关于c# - 如何在其他类的 lightswitch 中访问数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8413848/

相关文章:

c# - 如何找出 Application_End 在 Azure 应用服务上触发的原因

javascript - 为什么我的 JavaScript switch 语句不起作用?

xaml - Lightswitch - 如何重用现有资源?

c# - 如何获得所有女性?

c# - 正则表达式 : extract numbers separated by commas from strings

c# - 当用户点击网站链接时自动填写用户名+密码

C# 从 LinQ XDocument 加载数据表

java - 如何使用带有多个参数的 switch()?

python - 如何在python case语句中运行代码块

javascript - Lightswitch HTML 客户端 : How to re-render an item (re-execute postRender callback)