Several Issues with CRUD - [Computed Column / Trigger / Time Type Field] in MS SQL Database

Hi There,
I'd like to draw your attention on this interesting (hopefully!) problem. Its not specific to Radzen Studio Or Blazor Studio. I believe this is more wider - to EF & Blazor etc etc... But keen to get your opinion on Workarounds, if any.

To reproduce:

Created Empty DB and 3 tables. 2 under [msi] schema and 1 under [Audit] schema. They look like below... (DDL - Create Tables/schema and DML - Data Insert) are attached.Processing: UITest - Edited Model.zip...

Now trying to generate CRUD via Radzen Blazor Studio.

All Codes are available Here: Click Here

image

Issues:

  1. First of all I created simple CRUD with click> click> click In Radzen Blazor studio. Final Outcome (As attached entire solution & project in - UITest - No Modification of Radzen Code.zip) - Debug/Run Error.
    ~ I guess this has something to do with Entity Framework's way of interpreting with Identity & Computed column etc.

  2. So, now I went ahead and altered, my computed column (also is the Primary key) in Model from
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)] to [DatabaseGenerated(DatabaseGeneratedOption.None)]

also, added [DatabaseGenerated(DatabaseGeneratedOption.None)] on ID (int identity) columns.

~ With that modification, now program started running. (Modified solution attached in - UITest - Edited Model.zip)

But - Here I guess we have some issues / bugs to fix.... Display pages work for both table but edit page works for none. So, far I assume these are the areas causing trouble -

(a) For master table - There is no trigger but still not working because radzen/blazor studio is not generating child element for TimeSpan field. Could we please fix it, or may be you can share some guidance on while component to use and how to bind TimeSpan field?

(b) For Header Table - It a simple one but still Edit not working because of Trigger and Computed Column & Identity Column. I was assuming Blazor Studio is able to handle it but seems not. Could you please have a look and share some guidance for this?

Thank you so much in advance,

Hi @Rk_M,

Check my reply in your other thread for more information about first part of the problem - wrong attributes for your models because of wrongly identified database meta data. You can use Radzen IDE instead for now for this database instead Radzen Blazor Studio.

About the second part of your question - not able to edit/update records. I've scaffolded your database + CRUD pages using Radzen IDE instead Radzen Blazor Studio (to avoid the meta data problems) and I've noticed the following:
Editing of T_DM_DATAHEADER will not work since you have the following:

  public partial class MsiTDmDataheader
  {
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID
    {
      get;
      set;
    }

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public string DATAHEADER_DB_ID
    {
      get;
      set;
    }
    ...

Radzen will not create any UI for this property/field since it's identity - the value should be generated by your database. When you attempt to edit you will get the following exception:

Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot update identity column 'ID'.

Not sure what's the reason behind this setup however usually the table primary key is identity while in your case you have different field for primary key which should be set in order to operations like Add/Edit to be successful. If you extend your DbContext with the following the update will be sucessful:

  builder
                .Entity<MsiTDmDataheader>()
                .Property(e => e.ID)
                .ValueGeneratedOnAddOrUpdate()
                .Metadata.SetAfterSaveBehavior(Microsoft.EntityFrameworkCore.Metadata.PropertySaveBehavior.Ignore);


Thanks a lot. I consolidated my feedbacks, on other post.

Foreign Key Relation Not Creating [DropDown] automatically in Blazor Studio - Radzen Blazor Studio - Radzen