I have ran into an exception being thrown when there is a NULL value for one of the two fields that make up the composite FK. System.InvalidOperationException: The EDM instance of type '[DbApp.Models.DbApp.ParentTable Nullable=True]' is missing the property FieldId. What is the proper way to resolve this issue?
For example, Col1 allows nulls, where Col2 doesn't. Together make up the PK/FK.
When does this exception occur? During update or read operations? Also isn the diagram you have drawn valid? Table1 refers to invalid composite key.
@korchev - it's a minimal example, and it is a valid and permissible (but kind of gross) FK. What's not included are the rest of the columns in the referencing table (table 1). Table 1 also has columns 3,4,5 and a few others. Columns 2 and 3 are FK to table 3. Columns 1 and 4 FK to Table 4. Most of the rows in Table 1 have values in column 1.
The problem as I understand is when trying to view details for a table 1 record, when that record has a null value in column 1. The UI can list Table 1 records, but when clicking on the record, an exception is thrown. An exception is also thrown if trying to sort the list of table 1 records.
Got it. It seems to be an issue with the OData implementation. It fails when it couldn't find the related entity requested by the $expand parameter. We couldn't find a workaround except to avoid setting the $expand parameter altogether.
@korchev - but NULL != NULL, so the FK will never match any PK, so generated code should not bother attempting (and failing).
Is this code generation something we can adjust or tweak, or at least something we can patch after it's generated?
You can adjust any generated code by using the Ignore list. However I don't think anything in the generated controllers or model will prevent that error. It happens in the OData implementation which Radzen doesn't generate.
The only solution I found is to avoid setting the $expand parameter to Table2 when invoking the getTable1 method:
@korchev thanks for the info and suggestions.
@jbhakta - can you try using the MSSql datasource instead if OData and see if that addresses some of the issues you are seeing? If not, we can try some of these suggestions.
@StingyJack Radzen is using OData as service layer when exposing database like MSSQL, MySQL etc.
Then is there a difference in the selections on the Edit Data source screen?
There is a data source invoke action in your edit screen with $expand parameter. As already suggested you should remove all $expand parameters to avoid this exception.
I mean is an oData interface generated when I choose MSSql as the datasource type?
Yes, the application service layer is OData.
When trying to update a row's column value to NULL in Table1 I get a similar exception, and I'm trying to find the same $expand parameter setting but I don't see it. It does update it in the database, but just throws the error notification in the UI.
I was expecting to see a similar setup for the $expand parameter listed here:
I noticed I could remove the following line of code, but then I would have to put the file in the ignore list. How can I do this from radzen?
Request.QueryString = Request.QueryString.Add("$expand", "Table2");
Unfortunately modifying and ignoring the controller is the only option at the moment because of the OData issue.