Data annotations in metadata class

Greetings,
we are trying with no success to put data annotations for the model used by a SfGrid component in a metadata class.
If we put the annotations directly in the model class (as the [Required] annotation in the example below) it works like a charm:

public class MyModel
{
public int Id { get; set; }

[Required]
public string Description { get; set; }
}

The problem is that we are using Entity Framework and database-first approach, so we cannot put annotation directly in the model class, which is auto-generated.
We use a partial class and a metadata class, all in the same namespace of the auto-generated model class:

[MetadataType(typeof(MyModelMetadata))]
public partial class MyModel { }

public class MyModelMetadata
{
[Required]
public string Description { get; set; }
}

In this case the [Required] annotation is ignored by SfGrid.
Does Blazor SfGrid support data annotation in metadata class at all? The use of metadata classes is very common in database-first approach, so I'm wondering if there is any other way to solve the problem.

(In the forum there is a similar thread, but it's about ASP.NET MVC, not Blazor.)




2 Replies

RN Rahul Narayanasamy Syncfusion Team July 17, 2020 02:43 PM UTC

Hi DotCom, 
 
Greetings from Syncfusion. 
  
We have validated your query with the provided information and we have considered this requirement “need to provide dataannotation support for meta data class” as an feature and added this feature request to our database. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts. This feature will be included in our upcoming Volume 3, 2020 main release. Until then we appreciate your patience.   
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.   
  
 
Regards,
Rahul 
 
 
 



MA Mason July 26, 2022 03:50 PM UTC

Hi DotCom,


Basically, you need to follow the guidance here and call this line of code at OnInitialized. Microsoft chose to do it this way, but I recommend complaining in the GitHub lol.

Validation for MetadataType · Issue #39938 · dotnet/aspnetcore · GitHub


Loader.
Up arrow icon