访问变量普通项目LightSwitch中设置从服务器项目 [英] Access Variables set in Common Project From Server Project in Lightswitch

查看:160
本文介绍了访问变量普通项目LightSwitch中设置从服务器项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我重做了一些code到previous问题,但是相同的基本问题依然。我所试图做的是这样的:当我的LightSwitch应用程序启动通过 Application.cs 我使用的方法 Application_LoggedIn()来调用函数在我的共同项目,以获得所有用户具有访问(这个数据是存储在一个表)。

So I have redone some of the code to the previous question, however the same underlying issue remains. What i am trying to do is this: When my lightswitch application launch through Application.cs i am using a method Application_LoggedIn() to call a function in my Common Project to get all the location a user has access to (this data is stored in a table).

客户端项目 - Application.cs

Client Project - Application.cs

  partial void Application_LoggedIn()
    {
        Secure.Membership aa = new Membership();
        aa.membership();
    }

共同的项目 - 在调用该方法后,我再运行我的查询中的成员()函数来获取所有用户有权访问的位置。它们被存储在三个表:estateList,deptList,GROUPLIST;

Common Project - After calling the method, i then run my queries in the membership() function to get all the location a user has access to. They are stored in three list: estateList, deptList, groupList;

public void membership() {

    List<int> estateList = new List<int>();
    List<int> deptList = new List<int>();
    List<int> groupList = new List<int>();

    var dws = Application.Current.CreateDataWorkspace().sspData;
    String uName = Application.Current.User.Identity.Name;
    try
    {
        var qryUser = (from a in dws.aspnet_Users
                       where a.UserName == uName
                       select a).Execute().Single();

        int membershipId = qryUser.Payroll_MembershipGroup.Id;
        var qryOrgMember = (from a in dws.PayrollOrg_MembershipGroups
                            where a.Payroll_MembershipGroup.Id == membershipId
                            select a).Execute().ToList();

        foreach (var x in qryOrgMember)
        {

            if (!estateList.Contains(x.Payroll_Organisation.Estate1.ID))
            {
                estateList.Add(x.Payroll_Organisation.Estate1.ID);
            }
            if (!deptList.Contains(x.Payroll_Organisation.Estate1.ID))
            {
                deptList.Add(x.Payroll_Organisation.Department1.ID);
            }
            if (!groupList.Contains(x.Payroll_Organisation.Estate1.ID))
            {
                groupList.Add(x.Payroll_Organisation.Payroll_Group1.ID);
            }
        }
    }
    catch (Exception e)
    {

        Debug.WriteLine("***************" + e.InnerException);
    }

}

这样做是为了能够从我的服务器项目中访问3列出(房地产,部门,组),这样我就可以使用列表如下图所示在我的实体进行过滤后,想什么我。

What i would like after doing this is to be able to access the 3 lists (estate,dept,group) from inside my server project so i can use the list to perform filters on my entities as shown below.

partial void Employee_Employs_Filter(ref Expression<Func<Employee_Employ, bool>> filter)
{ 
   filter = e => estateList.Contains(e.Estate1.ID) && deptList.Contains(e.Substantive_Department) && groupList.Contains(e.Payroll_Group1.ID);
}

这是我想做的事情,我有问题。任何建议将受到欢迎。我试图做的是在我的常见项目来创建一个静态类然而设定值作为一个用户正确地指出的那样,我不能这样做,因为这将是空当我试图从我的服务器项目中调用它。请帮我在这里,这是我与这个应用程序有一个大问题,是唯一的剩余部分。先谢谢了。

This is what i want to do and i am having problem. Any suggestion would be welcomed. What i tried to do is to create a static class in my Common Project and set the values however as one user rightly pointed out, i cannot do that as it will be null when i try to call it from inside my Server Project. Please help me out here, this is a big issue i am having with this application and is the only remaining part. Thanks in advance.

的**的 * 的**的 * 的**的 * 的***的 过滤器$ C $服务器正面c *
@Duran这是我不得不在服务器端。

************ Filter code on server side* @Duran this is what i had on the server side.

public List<User> membership() {

    List<User> aList = new List<User>();
    User aUser = new aUser();


    var dws = Application.Current.CreateDataWorkspace().sspData;
    String uName = Application.Current.User.Identity.Name;
    try
    {
        var qryUser = (from a in dws.aspnet_Users
                       where a.UserName == uName
                       select a).Execute().Single();

        int membershipId = qryUser.Payroll_MembershipGroup.Id;
        var qryOrgMember = (from a in dws.PayrollOrg_MembershipGroups
                            where a.Payroll_MembershipGroup.Id == membershipId
                            select a).Execute().ToList();

        foreach (var x in qryOrgMember)
        {

            aUser.estateId = x.estateId
            auser.deptId = x.deptId;
            aUser.groupId = x.groupId;

            aList.add(aUser);
        }
    }
    catch (Exception e)
    {

        Debug.WriteLine("***************" + e.InnerException);
    }

    return aList;

}

public class User{

    public estateId{set;get:}
    public deptId{set;get:}
    public groupId{set;get:}

}

Now in my filter i would call the method membership() that returns a list<User>

partial void Employee_Employs_Filter(ref Expression<Func<Employee_Employ, bool>> filter)
{ 
    var x = membership();
    estId[int] = new [x.count()];
    deptId[int] = new [x.count()];
    groupId[int] = new [x.count()];

    for (int i=0; i<x.count();i++){
         estId[i] = x.elementAt(i).estateId;
         deptId[i] = x.elementAt(i).deptId;
         groupId[i] = x.elementAt(i).groupId;

    }

   filter = e => estId.Contains(e.Estate1.ID) && deptId.Contains(e.Substantive_Department) && groupId.Contains(e.Payroll_Group1.ID);
}

我已经把类似于上面的一个在我所有的表,这就是当我拿到计算器错误的过滤器。它的工作原理,当它在一个单独的表
但是当它是所有表不。我究竟做错了什么?

I have to put a filter similar to the one above on ALL my tables, thats when i get the stackoverflow error. It works when its on ONE table alone but not when it is on all the tables. What am i doing wrong?

推荐答案

尽管在 code 通用的项目是共享的客户的&安培; 服务器的项目,任何变量在那里创建有自己独立的实例,一个在客户的项目,和放大器;一个在的服务器的项目。

Even though the code in the Common project is "shared" between the Client & Server projects, any variables created there have their own separate instances, one in the Client project, & one in the Server project.

所以你没有真正访问的共享变量可言,这就是为什么当你在一层设置一个值,对其他层次的价值不能反映价值这一变化,因为他们实际上是两个不同的变量的实例。

So you're not really accessing a single shared variable at all, which is why when you set a value on one tier, the value on the other tier doesn't reflect that change in value, because they're actually two distinct instances of the variable.

这篇关于访问变量普通项目LightSwitch中设置从服务器项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆