Add database error with a one-to-many relationship

Hi

When I add a database with "Radzen Blazor for Visual Studio" and compare it to "Radzen Blazor Studio," it seems that "Radzen Blazor for Visual Studio" lacks some pieces of code, which prevents the creation of a one-to-many relationship.

With the database described in the image.

TestDB

The code generated with "Radzen Blazor Studio" for *Context.cs

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

            builder.Entity<Test.Models.Address.City>()
              .HasOne(i => i.Country)
              .WithMany(i => i.City)
              .HasForeignKey(i => i.CountryCode)
              .HasPrincipalKey(i => i.Code);
            this.OnModelBuilding(builder);
        }

The code generated with "Radzen Blazor for Visual Studio" for *Context.cs

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

Can you fix it?

Radzen Blazor for Visual studio should generate the exact same code as Radzen Blazor Studio (they share the same code generation engine). Also we couldn't reproduce this issue in both tools. If you have a subscription you could send us the SQL CREATE script of your database and we will test.

Hi korchev

My Test Database is very simple with 2 tables in the picture (Country, City). I test with MySQL and MSSQL, "Radzen Blazor for Visual Studio" always miss code for one-to-many relationship.

TestDB

-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema Address
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema Address
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `Address` DEFAULT CHARACTER SET utf8 ;
USE `Address` ;

-- -----------------------------------------------------
-- Table `Address`.`Country`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Address`.`Country` (
  `Code` VARCHAR(3) NOT NULL,
  `Name` VARCHAR(45) NULL,
  PRIMARY KEY (`Code`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Address`.`City`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Address`.`City` (
  `Id` INT NOT NULL,
  `Name` VARCHAR(45) NULL,
  `CountryCode` VARCHAR(3) NULL,
  PRIMARY KEY (`Id`),
  INDEX `fk_City_Country_idx` (`CountryCode` ASC) VISIBLE,
  CONSTRAINT `fk_City_Country`
    FOREIGN KEY (`CountryCode`)
    REFERENCES `Address`.`Country` (`Code`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Thanks! We will address it with the next release.

1 Like

Hi korchev

Thank you for updating "Radzen Blazor for Visual Studio" to the new version to fix the issues.

I have tested the new version of "Radzen Blazor for Visual Studio" and found that the code for entity relations is now available. However, compared to "Radzen Blazor Studio", the pages AddCity.razor, EditCity.razor, and City.razor are missing the "Country" data field.

Thanks. We will address that issue with the next release.

1 Like