简体   繁体   English

LightSwitch实体:更新外键属性的值

[英]LightSwitch Entity: Updating the Value of Foreign Key Property

I am struggling with how I do the following in LightSwitch. 我正在努力在LightSwitch中执行以下操作。 I am 'intercepting' the entity during the partial void tblStaffExtendeds_Updating(tblStaffExtended entity) and then pulling some data from our local ldap and trying to set one of the properties of the entity to a specific value, like so: 我在partial void tblStaffExtendeds_Updating(tblStaffExtended entity)期间“拦截”了该实体,然后从本地ldap提取了一些数据,并尝试将实体的属性之一设置为特定值,例如:

partial void tblStaffExtendeds_Updating(tblStaffExtended entity)
    {

        string ldapPath = @"LDAP://DC=myLDAP,DC=myLDAP";            
        string user = entity.GPEmployeeID.ToString();
        string[] props = { 
                            ActiveDirectoryInfo.strings.DISPLAYNAME, ActiveDirectoryInfo.strings.EMAIL, 
                            ActiveDirectoryInfo.strings.LOGONALIAS, ActiveDirectoryInfo.strings.PHONE, 
                            ActiveDirectoryInfo.strings.OFFICE, ActiveDirectoryInfo.strings.TITLE, 
                            ActiveDirectoryInfo.strings.GPEMPLOYEEID
                          };

        var propResults = ActiveDirectoryInfo.UserPropertySearchByGPEmpID(user, ldapPath, props);

        entity.tblAdminStaffType.StaffType = propResults[ActiveDirectoryInfo.strings.TITLE];
        entity.WorkEmail = propResults[ActiveDirectoryInfo.strings.EMAIL];
        entity.UserID = propResults[ActiveDirectoryInfo.strings.LOGONALIAS];
        entity.WorkPhone = propResults[ActiveDirectoryInfo.strings.PHONE];
   }

Now for fields like WorkEmail and WorkPhone this works fine as those properties are just strings and that is what I am getting from LDAP . 现在,对于诸如WorkEmailWorkPhone类的WorkEmail ,它可以正常工作,因为这些属性只是strings而这正是我从LDAP获得的。
However I do I go about setting the StaffType which is a reference to an Admin Table entry? 但是,我该如何设置StaffType ,它是对Admin Table条目的引用? LDAP returns a string which matches the description on the Admin Table but on the Entity I would need to set it to the correct ID, I am assuming. LDAP返回一个与管理表上的描述匹配的string ,但在实体上,我需要将其设置为正确的ID。

Is there someway to do this, short of creating "Look Up" methods to find the ID from the Admin Table by matching the Description to my String from LDAP ? 是否有某种方式可以做到这一点,而无需创建“查找”方法以通过将说明与LDAP我的String进行匹配来从管理表中找到ID?

The solution should look something like this: 解决方案应如下所示:

string title = propResults[ActiveDirectoryInfo.strings.TITLE];

var qryAdminStaffType = from st in DataWorkspace.ApplicationData.StaffTypes
                        where st.Title == title
                        select st;

entity.tblAdminStaffType.StaffType = qryAdminStaffType.FirstOrDefault();

In this example, I'm assuming that your data source is called ApplicationData (the LS default name), that the StaffTypes table holds your staff types, and that you are matching the Title attribute. 在此示例中,我假设您的数据源称为ApplicationData(LS默认名称), StaffTypes表包含您的人员类型,并且您与Title属性匹配。 Note that if there is no match to the title, FirstOrDefalt() will return null. 请注意,如果标题不匹配,则FirstOrDefalt()将返回null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM