当在 Lightswitch 中向父 table 添加新记录时,如何自动将新记录插入子 table?

How do I Automatically insert a new record into a child table when a new record is added to a parent table in Lightswitch?

我有一个 C# 中的 Lightswitch 桌面客户端应用程序。有一个名为 Participants 的父项 table/entity 和一个名为 HouseIncomes 的子项 table。 HouseIncomes 中的 field/properties 之一是名为 CurrentLevel 的字符串 属性,其选择列表为 Yes 和 No。当在 Participants parent table 中创建新记录时,一条记录如何在 CurrentLevel 字段中使用默认值 "Yes" 添加到子 HouseIncomes table?

使用 C#,这应该适用于您的场景:

打开您的数据源,单击 "Write Code" 和 select 中的 Participants_Inserted 选项。 (见下图)输入类似于此的代码:命名约定可能略有出入,但我猜到你的可能是什么:

    partial void Participants_Inserted(Participants entity)
    {
        HouseIncome houseIncome = DataWorkspace.YOURDATASOURCE.HouseIncomes.AddNew();
        houseIncome.Participants = entity; //THIS ASSIGNS THE FOREIGN KEY RELATIONSHIP TO ITS PARENT
        houseIncome.CurrentLevel = "Yes"; //FOR STRING
        houseIncome.CurrentLevel = true; //FOR BOOLEAN
    }

此代码正在插入您的子数据,自动链接到您的父数据,并将当前级别设置为您想要的值。

希望这对您有所帮助...