Search This Blog

Add Foreign Key to table and Display it by Mapping(i.e Displaying Corresponding Textual Field)

Serenity entities are more like SQL views. You can bring in fields from other tables with joins.

Add foreign key relation manually or by migration in database. 

Add foreign key field and its corresponding textual field in RowFields class at the bottom of childClassNameRow.cs

Add foreign key field and its corresponding textual field in childClassNameRow class as a property in childClassNameRow.cs

Add following attributes on foreign key field in childClassNameRow class
[ForeignKey("[SCHEMA].[Master_Table_name]", "Column_name")]
[LeftJoin("join_alias_name")]

Add following attributes on corresponding textual field in childClassNameRow class
[Expression("join_alias_name.textual_column_name_in_DB")]


Add textual field in childClassNameColumns.cs file. It will display the mapped text.

Add foreign key field in childClassNameForm.cs file. and add this attribute,
[LookupEditor(typeof(Entities.masterClassNameRow))]
Note: This attribute can be added in childClassNameRow.cs file to foreign key field. 

Add [LookupScript(nameof(masterClassNameRow))] attribute on masterClassNameRow class.

After these 2 recent steps, we will be able to see a dropdown in form.

If you have generated the code via SERGEN (with foreign key relation already
present in database)then you might only need to apply the last step.

Define A New Textual Field Value Inplace


Add Inplace, DialogType parameters in LookupEditor attribute in childClassNameForm.cs file, e.g.

[LookupEditor(typeof(Entities.masterClassNameRow), InplaceAdd = true, DialogType = "ModuleName.masterClassNameDialog")]


Note: This attribute can be added in childClassNameRow.cs file to foreign key field.


No comments:

Post a Comment

Web Statistics