RS changes names of relations

Hi @Thomas,

I understand that this is “very easy” for you however I can assure you that there is nothing we can do to guarantee navigation/invers property naming in such radical table structure changes. For sure there is something that triggers different oder and naming at your end however the only option I can suggest you is to abandon this workflow and never insert columns in the middle of the other column definitions requiring table restructure. Radzen cannot handle this case nor default EF scaffold.

Hello @enchev,
yes. i thought about that. And because its more "my little monk" and absolutly not necessary i will try to
change that and append columns to tables.

Thomas

I think this particular problem happens only when you insert a foreign key column before an existing foreign key column to the same table. This makes the new column appear before the old one and as a result it gets the name without suffix whereas the old one gets the suffix. If you remember this case you can append new foreign key columns to ensure the property names remain unchanged.

Hi @korchev,
yes. This is the best interpretation of the problem.
I think i must keep that in mind.
Thank you and @enchev for your time bringing clarity to this!

thanks

Thomas

Hello radzen team,
It happens again that scaffolding changes the name of navigation properties.
I only changed an foreignkey name from NOT NULL to NULL.
No change in the sort order of the colums or anything else.
after the not null/null change the navigation properties in the table are renamed from Fahrzeug to Fahrzeug1 and Fahrzeug1 to Fahrzeug. It costs me hours to correct the now wrong data access!

it is extremely difficult to develop with this... for me this is a major bug! ... in EF Scaffolding Database First.

I realized that this is a behaviour in EF and had nothing to do with Radzen.
But... i use radzen for scaffolding (INFER Database) and radzen generates the app context methods (Getxxx, Updatexxx, Deletexxx, ect.)

I love this functionality! I used them many times and i can not and will not waive them.

I read that it is possible to change the EF Scaffolding method to name navigation properties for my needs and overwrite the standard TABLE, TABLE1, TABLE2, TABLE3 and so on if you have more than one FK to the same table in one table.

My question is...
Can i use my own scaffolding method (i write a command line tool that i start manually or something like this. clear that this is my todo) without loosing the generated get, delete, update, create functionality in the radzen generated xxxdbService.cs?
Is there any way to realize this? (your side i think!? i will do what i can ...if i can do anything. We can talk about the possibilities whatever they are.)
e.g. not infer but start the xxxdbService.cs generating process on an existing context?
perhaps as a new check box ("use existing context" or something else) when selecting "data" from menu and then select "My Datasources".

Kind Regards
Thomas

@Thomas, there are no changes in Radzen IDE scaffolding for years.

I'm not aware of such.

Hi @enchev,

I know. as i said... its not a radzen problem. Its EF Scaffolding.
There are users worldwide which have the same problem. Microsoft/EF developers statement: "EF Scaffolding is not made for the continous scaffolding of database first approaches" :roll_eyes:

Yes. i thought that this is not possible at the moment. Can you imagine to offer such a functionality in a form i have suggested above?

possibly against payment...

Thomas

if you would like to do that we can discuss it via mail or anything else..

Thomas

@Thomas, our entire new development is related to Radzen Blazor Studio - we do not plan any new features for Radzen IDE.

I'm afraid also that in both Radzen Blazor Studio and Radzen IDE the process of scaffolding database is exactly the same, if you need to infer new structure from your database your DbContext file will be overwritten unless you have extra code in a partial class.

@enchev, yes. im working on changing to RBS.
The DBContext must be overwritten. All clear.

But Scaffolding changes the Names of Navigation Properties. And this is horrible.
Let me explain...

You got a Table (Cars) with 2 FK's to another Table (Drivers)
because one Car can have 2 Drivers (Main Driver and Passenger)

Tables:
Car

CarId INT IDENTITY(1, 1) NOT NULL
DriverMainId INT NULL
PassengerId INT NULL
... and whatelse

Driver

DriverId INT IDENTITY(1, 1) NOT NULL
Name NVARCHAR(50)
... and whatelse

Scaffolding generates Model Class
Car.cs

[Table("Car", Schema = "dbo")]
public partial class Car
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CarId
{
get;
set;
}
public int DriverMainId
{
get;
set;
}
public Driver Driver { get; set; }

public int PassengerId
{
  get;
  set;
}
public Driver Driver1 { get; set; }   // Scaffolding only sets numbers behind the Tablename

}

Now you are programming code like

string GetMainDriverNameFromCar(int carId)
{
return (from qry in dbcontext
.Cars
.Include(x=>x.Driver) // The MainDriver Navigation Property
where qry.CarId == carId
Selectqry.Driver.Name).SingleOrDefault();
}

string GetPassengerNameFromCar(int carId)
{
return (from qry in dbcontext
.Cars
.Include(x=>x.Driver1) // The Passenger Navigation Property
where qry.CarId == carId
Selectqry.Driver1.Name).SingleOrDefault();
}

All fine. You wrote large Amount of Code that will use the Driver and Driver1 NavProperty cause you know... Driver = MainDriver Driver1 = Passenger.

But now... You modify the Car Table. Insert another FK

Car

CarId INT IDENTITY(1, 1) NOT NULL
DriverMainId INT NULL
PassengerId INT NULL
... and whatelse
Passenger2Id INT NULL

And scaffolding may change the Navigation Property Name like this:
Car.cs

[Table("Car", Schema = "dbo")]
public partial class Car
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CarId
{
get;
set;
}
public int DriverMainId
{
get;
set;
}
public Driver Driver1 { get; set; }

public int PassengerId
{
  get;
  set;
}
public Driver Driver2 { get; set; }   // Scaffolding only sets numbers behind the Tablename

public int Passenger2Id
{
  get;
  set;
}
public Driver Driver { get; set; }   // Scaffolding only sets numbers behind the Tablename

}

Now:
Driver is the New Second Passenger
Driver1 is the DriverMain
Driver2 is the Passenger

Youre existing code compiles fine. But the Data you get from the existing Methods is completly wrong!

  1. GetMainDriverNameFromCar(int carId) returns the Name of the new Second Passenger
  2. GetPassengerNameFromCar(int carId) returns the Name of the DriverMain

But you dont notice that at the first Look. Only Testing reveals that.
And then you cann change all existing Code that accesses Driver & Driver1 to
-Driver is now Driver1
-Driver1 is now Driver2

That costs hours and features must be tested again that runs perfect for ages.

That is what Ef Scaffolding do.

THIS HAS NOTHING TO DO WITH Radzen BS OR Radzen Studio!

But there is a way out of this.

From StackOverFlow:
Extend IDesignTimeServices and add a service for ICandidateNamingService. This allows you to control the naming of the Navigation Properties during scaffolding. In the CustomCandidateNamingService class, you can define your own logic for generating the navigation property names. For example, you could check if a navigation property name already exists and, if so, append a unique identifier instead of a number.

This is what i mean.

My question is:
Can you implement the possibility that i can write such a "custom" scaffolding and generate the Model Classes and Context manually
without losing the Methods in the Radzen generated DBService.c (Getxxx, Deletexxx, Updatexxx, ect.)
The Scaffolding (EF Generates Model Classes & DBContext Class) and the Radzen Generation of DBService.cs
runs now in 1 Step (Radzen: Infer and Generate).
What i wish is that these Processes can be done or not in 2 Steps.
I will do the scaffolding and then Radzen: Generate the DBService.cs without Infering (Scaffolding) the Database.
Perhaps from the DBContext Class that i generate.

Kind regards

Thomas

@Thomas I would like to remind you that we've spent days trying to replicate the problem using your own instructions and your own database I was unable to replicate it. I'm afraid that we cannot add anything else on this topic. Radzen also is not using IDesignTimeServices nor ICandidateNamingService when scaffolding database metadata. I'm closing this thread.