Relationships not identified by blazor studio - work in radzen studio

I'm trialling blazor studio but have hit a similar issue to here - Issue with Foreign Keys Not Being Defined in Detail Grids of Master-Detail Layouts - #4 by enchev

I have an mssql backend with foreign key relationships defined

But the relationships aren't recognised when I infer schema and try to generate any of the parent-child crud pages

the subpage/child just lists every record in the child table - and the relationship/key field in the details grid is some random field from the parent table, not the one defined in the fk in the db

I downloaded the community version of radzen studio, and that DOES recognise the relationship and adds the correct filters to the components

Is there a limitation in blazor studio that i need to consider?

We are not aware of such limitation. Without database schema I cannot add any additional comments.

I think it's due to the schema not being dbo

my tables are in a custom schema - i just tried creating them in dbo in a dummy database and blazor studio identified the relationships correctly

my copy of blazor studio does not pick up the following relationships correctly - it identifies theres a relationship but there's no drop down to select the 'label' field when generating CRUD pages (like in the screenshot i pasted above)

create schema test authorization dbo
go

/****** Object:  Table [test].[child_table]    Script Date: 5/11/2024 11:25:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [test].[child_table](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parent_id] [int] NOT NULL,
	[child_code] [nchar](10) NOT NULL,
 CONSTRAINT [PK_child_table] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [test].[grandchild_table]    Script Date: 5/11/2024 11:25:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [test].[grandchild_table](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[child_id] [int] NOT NULL,
	[grandchild_code] [nchar](10) NOT NULL,
 CONSTRAINT [PK_grandchild_table] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [test].[parent_table]    Script Date: 5/11/2024 11:25:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [test].[parent_table](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nchar](10) NOT NULL,
 CONSTRAINT [PK_parent_table] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [test].[child_table] ON 
GO
INSERT [test].[child_table] ([id], [parent_id], [child_code]) VALUES (1, 1, N'strat_01  ')
GO
INSERT [test].[child_table] ([id], [parent_id], [child_code]) VALUES (2, 1, N'strat_02  ')
GO
INSERT [test].[child_table] ([id], [parent_id], [child_code]) VALUES (4, 2, N'strat_08  ')
GO
INSERT [test].[child_table] ([id], [parent_id], [child_code]) VALUES (3, 3, N'strat_04  ')
GO
SET IDENTITY_INSERT [test].[child_table] OFF
GO
SET IDENTITY_INSERT [test].[grandchild_table] ON 
GO
INSERT [test].[grandchild_table] ([id], [child_id], [grandchild_code]) VALUES (1, 1, N'net_01    ')
GO
INSERT [test].[grandchild_table] ([id], [child_id], [grandchild_code]) VALUES (2, 2, N'net_02    ')
GO
SET IDENTITY_INSERT [test].[grandchild_table] OFF
GO
SET IDENTITY_INSERT [test].[parent_table] ON 
GO
INSERT [test].[parent_table] ([Id], [name]) VALUES (1, N'project 1 ')
GO
INSERT [test].[parent_table] ([Id], [name]) VALUES (2, N'project 2 ')
GO
INSERT [test].[parent_table] ([Id], [name]) VALUES (3, N'project 3 ')
GO
SET IDENTITY_INSERT [test].[parent_table] OFF
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_child_table]    Script Date: 5/11/2024 11:25:25 AM ******/
CREATE UNIQUE NONCLUSTERED INDEX [IX_child_table] ON [test].[child_table]
(
	[parent_id] ASC,
	[child_code] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_grandchild_table]    Script Date: 5/11/2024 11:25:25 AM ******/
CREATE UNIQUE NONCLUSTERED INDEX [IX_grandchild_table] ON [test].[grandchild_table]
(
	[child_id] ASC,
	[grandchild_code] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
ALTER TABLE [test].[child_table]  WITH CHECK ADD  CONSTRAINT [FK_child_table_parent_table] FOREIGN KEY([parent_id])
REFERENCES [test].[parent_table] ([Id])
GO
ALTER TABLE [test].[child_table] CHECK CONSTRAINT [FK_child_table_parent_table]
GO
ALTER TABLE [test].[grandchild_table]  WITH CHECK ADD  CONSTRAINT [FK_grandchild_table_grandchild_table] FOREIGN KEY([child_id])
REFERENCES [test].[child_table] ([id])
GO
ALTER TABLE [test].[grandchild_table] CHECK CONSTRAINT [FK_grandchild_table_grandchild_table]
GO

I've tested this schema using both Radzen Studio and Radzen Blazor Studio and both scaffolded properly your relationships:

Radzen Studio:



Radzen Blazor Studio:



I can't tell from your screenshots whether its working correctly or not

here's the version info
blazor studio - 1.34.3
sql - Microsoft SQL Azure (RTM) - 12.0.2000.8 Oct 2 2024 11:51:41 Copyright (C) 2022 Microsoft Corporation

here are the problems i see

  1. when generating the parent-child crud pages there is no drop down for selecting the label field for the relationship column (see img in original post)

  2. when looking at the running site it doesn't filter the child records at all. Every parent shows every child record irrespective of which parent_id the child has & the 'parent' column isn't mapped to the correct column (because it doesn't give me the option to select the label field when generating the crud page)

test.child_table
id	parent_id	child_code
1	1			strat_01  
2	1			strat_02  
4	2			strat_08  
3	3			strat_04  

parent id 1 shouldn't be showing child 3 & 4

parent id 2 should only show child 4

parent id 3 should only show child 3

also note how the parenttable column in the child grid is blank

what's the queries that blazor studio runs to get the relationship metadata?

Relations are defined in the the DbContext.

Radzen Studio:

Radzen Blazor Studio:

From the screenshots in my previous reply you can check the lookups to parent available when editing child records.

sorry about the reply delay - mine are different. For some reason the entities are appended with a 1 which means they dont find anything (?). But only if it's the non 'dbo' schema.

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<TestSchema.Server.Models.test_.TestGrandchildTable>()
              .HasOne(i => i.ChildTable1)
              .WithMany(i => i.TestGrandchildTable)
              .HasForeignKey(i => i.ChildId)
              .HasPrincipalKey(i => i.Id);

            builder.Entity<TestSchema.Server.Models.test_.TestChildTable>()
              .HasOne(i => i.ParentTable1)
              .WithMany(i => i.TestChildTable)
              .HasForeignKey(i => i.ParentId)
              .HasPrincipalKey(i => i.Id);
            this.OnModelBuilding(builder);

how does radzen infer this information? what's the query that's run against information_schema? I can try running that manually

adding the identical tables from the dbo schema results in the correct mappings

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<TestSchema.Server.Models.dbo_.ChildTable>()
              .HasOne(i => i.ParentTable)
              .WithMany(i => i.ChildTable)
              .HasForeignKey(i => i.ParentId)
              .HasPrincipalKey(i => i.Id);

            builder.Entity<TestSchema.Server.Models.dbo_.GrandchildTable>()
              .HasOne(i => i.ChildTable)
              .WithMany(i => i.GrandchildTable)
              .HasForeignKey(i => i.ChildId)
              .HasPrincipalKey(i => i.Id);
            this.OnModelBuilding(builder);

My previous post demonstrate the scaffold result exactly from the schema you've posted which is not using dbo but test as a SQL db schema name.