Master Detail Hierarchy Not Filtering Child Data

When I scaffold a new Master/Detail Hierarchy page it is not filtering the child data and instead returning all results. Here’s the code it is generating:

        protected MyProject.Server.Models.MyDatabase.MyParentTable myParentTableChild;
        protected async Task GetChildData(MyProject.Server.Models.MyDatabase.MyParentTable args)
        {
            myParentTableChild = args;
            var MyChildTableResult = await MyDatabaseService.GetMyChildTable();
            if (MyChildTableResult != null)
            {
                args.MyChildTable = MyChildTableResult.Value.ToList();
            }
        }

I then have to add filtering to GetMyChildTable(). Can the filtering be added automatically when scaffolding these pages from RBS?

Usually the code looks like this:

protected TestSample.Models.Sample.Order orderChild;
protected async Task GetChildData(TestSample.Models.Sample.Order args)
{
  orderChild = args;
  var OrderDetailsResult = await SampleService.GetOrderDetails(new Query { Filter = $@"i => i.OrderId == {args.Id}", Expand = "Order,Product" });
  if (OrderDetailsResult != null)
  {
    args.OrderDetails = OrderDetailsResult.ToList();
  }
}

Make sure you have primary keys and relations setup properly.

All the keys and relations are set up properly. This worked just fine in Radzen Studio. Is there something wrong with my install of RBS?

Also, that syntax doesn’t work for me. I had to set up the query like this:

new Query { Filter = $"OrderId eq {args.Id}", Expand = "Order,Product" }

I can consistently reproduce this in both Radzen Blazor Studio and the plugin for Visual Studio using a variety of options.

In addition, I’ve noticed a few other issues with scaffolding Master/Detail Hierarchy pages:

  • When renaming the page during scaffolding, the Edit and Add pages are also updated as expected, but the code calling them from the child template does not get updated and the fields on the Edit and Add pages don’t get generated, but leave a malformed ChildContent tag
  • The Add page does not pass in the parent key value, so the parent has to be selected. I would expect this page to be generated with a parameter accepting the key value and the corresponding property automatically set to that value.

In this case your app is WebAssembly however I’m unable to replicate such problem using our Sample database and latest version of RBS:

Hello, I am trying out a trial version of RBS and I am able to reproduce a similar issue. I am using MSSQL as datasource. When I generate master/detail datagrid page with database that has only one schema everything works as intended.

The problem comes when I add tables from a different schema.
For example, there are two schemas A and B. Schema A has tables C and D, while Schema B has tables C and E. Both schema tables have one to many relation. When I create master/detail datagrid using tables C and D from schema A the function which should get children is generated without a query (just like @GallusRoboticus has in his initial post)

Is this intentional or not?

Here is what I’ve tested:
```
/====================================================
Two schemas (A, B) each with a 1-to-many relationship:
A.C (1) -> A.D (many)
B.C (1) -> B.E (many)
====================================================
/

SET NOCOUNT ON;
GO

/*====================================================

  1. Create Schemas
    ====================================================*/
    IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'A')
    EXEC('CREATE SCHEMA A');
    GO

IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'B')
EXEC('CREATE SCHEMA B');
GO

/====================================================
2) Drop tables (child first, then parent)
====================================================
/
IF OBJECT_ID('A.D', 'U') IS NOT NULL DROP TABLE A.D;
IF OBJECT_ID('A.C', 'U') IS NOT NULL DROP TABLE A.C;

IF OBJECT_ID('B.E', 'U') IS NOT NULL DROP TABLE B.E;
IF OBJECT_ID('B.C', 'U') IS NOT NULL DROP TABLE B.C;
GO

/====================================================
3) Create tables for Schema A (A.C -> A.D)
====================================================
/
CREATE TABLE A.C
(
CId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_A_C PRIMARY KEY,
Name NVARCHAR(100) NOT NULL,
CreatedDate DATETIME2 NOT NULL CONSTRAINT DF_A_C_CreatedDate DEFAULT SYSDATETIME()
);

CREATE TABLE A.D
(
DId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_A_D PRIMARY KEY,
CId INT NOT NULL, -- FK to A.C (one C has many Ds)
Description NVARCHAR(200) NOT NULL,
Amount DECIMAL(10,2) NOT NULL,
CreatedDate DATETIME2 NOT NULL CONSTRAINT DF_A_D_CreatedDate DEFAULT SYSDATETIME(),

CONSTRAINT FK_A_D_A_C
    FOREIGN KEY (CId) REFERENCES A.C(CId)
    ON DELETE CASCADE
    ON UPDATE NO ACTION

);

CREATE INDEX IX_A_D_CId ON A.D(CId);
GO

/====================================================
4) Create tables for Schema B (B.C -> B.E)
====================================================
/
CREATE TABLE B.C
(
CId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_B_C PRIMARY KEY,
Title NVARCHAR(100) NOT NULL,
IsActive BIT NOT NULL CONSTRAINT DF_B_C_IsActive DEFAULT (1)
);

CREATE TABLE B.E
(
EId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_B_E PRIMARY KEY,
CId INT NOT NULL, -- FK to B.C (one C has many Es)
Code NVARCHAR(50) NOT NULL,
CreatedOn DATE NOT NULL,

CONSTRAINT FK_B_E_B_C
    FOREIGN KEY (CId) REFERENCES B.C(CId)
    ON DELETE CASCADE
    ON UPDATE NO ACTION

);

CREATE INDEX IX_B_E_CId ON B.E(CId);
GO

/====================================================
5) Populate Schema A (parents first, then children)
====================================================
/
INSERT INTO A.C (Name)
VALUES ('Alpha'), ('Beta'), ('Gamma');

-- Each A.C gets multiple A.D rows (1-to-many)
INSERT INTO A.D (CId, Description, Amount)
VALUES
(1, 'Alpha - line 1', 10.00),
(1, 'Alpha - line 2', 25.50),
(2, 'Beta - line 1', 99.99),
(2, 'Beta - line 2', 15.00),
(2, 'Beta - line 3', 5.25),
(3, 'Gamma - line 1', 42.42);
GO

/====================================================
6) Populate Schema B (parents first, then children)
====================================================
/
INSERT INTO B.C (Title, IsActive)
VALUES
('Item One', 1),
('Item Two', 0),
('Item Three', 1);

-- Each B.C gets multiple B.E rows (1-to-many)
INSERT INTO B.E (CId, Code, CreatedOn)
VALUES
(1, 'ONE-001', '2024-01-01'),
(1, 'ONE-002', '2024-01-15'),
(2, 'TWO-001', '2024-02-01'),
(3, 'THR-001', '2024-03-10'),
(3, 'THR-002', '2024-03-11'),
(3, 'THR-003', '2024-03-12');
GO

/====================================================
7) Verification (optional)
====================================================
/
SELECT 'A.C' AS TableName, * FROM A.C ORDER BY CId;
SELECT 'A.D' AS TableName, * FROM A.D ORDER BY CId, DId;

SELECT 'B.C' AS TableName, * FROM B.C ORDER BY CId;
SELECT 'B.E' AS TableName, * FROM B.E ORDER BY CId, EId;
GO
```

If my understanding of the master/detail datagrid is correct then only the items in red zone should be shown:

Ah! I completely misseed that! Here is what is not generated properly in this template - we will fix it for the next update (next week):

Great, I’ve tested that query as well and it it works.