I've got a two tables that are connected by a Foreign Key.
public class Vitals
{
[SQLite.AutoIncrement, SQLite.PrimaryKey]
public int vitalsid { get; set; }
public string Bps { get; set; }
public string Bpd { get; set; }
public int pid { get; set; }
[ForeignKey("pid")]
public Patient Patient { get; set; }
}
And :
public class Patient
{
[SQLite.AutoIncrement, SQLite.PrimaryKey]
public int pid { get; set; }
[Display(Name = "First Name", GroupName = "Name")]
[DataFormDisplayOptions(RowOrder = 0, ItemsOrderInRow = 0)]
public string fname { get; set; }
[Display(Name = "Last Name", GroupName = "Name")]
[DataFormDisplayOptions(RowOrder = 0, ItemsOrderInRow = 1)]
public string lname { get; set; }
[Display(Name = "Address1", GroupName = "Address")]
[DataFormDisplayOptions(RowOrder = 1, ItemsOrderInRow = 0, ColumnSpan = 2)]
public string Address1Item { get; set; }
[Display(Name = "Address2", GroupName = "Address")]
[DataFormDisplayOptions(RowOrder = 1, ItemsOrderInRow = 1, ColumnSpan = 2)]
public string Address2 { get; set; }
[Display(GroupName = "Address")]
[DataFormDisplayOptions(RowOrder = 2, ItemsOrderInRow = 0, ColumnSpan = 2)]
public string City { get; set; }
[Display(GroupName = "Address")]
[DataFormDisplayOptions(RowOrder = 2, ItemsOrderInRow = 1)]
[StringLength(2, ErrorMessage = "State Abbr should not exceed 2 characters")]
public string State { get; set; }
[Display(GroupName = "Address")]
[DataFormDisplayOptions(RowOrder = 2, ItemsOrderInRow = 2, ColumnSpan = 2)]
public string PostCode { get; set; }
}
When I selected an item from the Vitals collection view, the data is show on the SfDataForm. The Patient fields are displayed, but there is no data.
How can I fix this issue and show the data from both tables?
Thank you.
Hi Frederick,
Based on the information provided, we have checked your query. We attempted to create a simple sample using the code snippets you shared, but we were unable to replicate the reported issue on our end due to missing codes related to the SQLite database.
The sample we created is attached here for your reference. To assist you further, please review the sample. If possible, please modify it according to your specific requirements, ensuring that the sample is in a runnable state and accurately replicates the issue you are facing.
Regards,
Vidyalakshmi M.
Vidyalakshmi M,
I ran your example and I am not seeing the issue of using a SfDataForm with SQLite tables that are joined by a Foreign Key.
When I run my program, both the Vitals table and the Patient table are displayed in the DataForm. However, only the Vitals data is displayed and there is no associated Patient data displayed.
Here is a screen shot. The Vitals section of the dataform has data, but the Patient section does not.
Thanks
Any update on a response that will address the issue of a SfDataForm that uses a SQLite foreign key?
Hi Frederick,
#Regarding DataForm using nested class dataobject
We recommend initializing the value for the nested class (Patient) to retrieve the respective class property value for display in the view. Please refer to the code snippet for your reference.
Code Snippet
|
public class Vitals { public int vitalsid { get; set; } = 1;
public string Bps { get; set; } = "120";
public string Bpd { get; set; } = "80";
public int pid { get; set; } = 1;
[ForeignKey("pid")] public Patient Patient { get; set; } = new Patient(); } |
Please refer to the modified sample in the attachment. Please let us know if you have any concerns.
Regards,
SaiGanesh Sakthivel