I have a database ( existing application) that uses shortint SQL datatype for its boolean values.
The application does this not always in its own application so in one table a shortint is simply a shortint and some other tables a shortint is a treated as an boolean ( 0 and 1 ) .
Infering the database with Radzen I want to change that to map the shortint in some tables to a boolean.
How to ? so that I do not end with adding these model and controllers to the exclude list and changing the generated model code .
is some kind of override in a custom.cs partial possible ?
Yes, Radzen does not recognize custom columns in Angular applications (but it does in Blazor ones). The other suggestion (modifying the data source JSON file) should work in design time though.
Modified Json and it does compile but getting erro:
System.InvalidCastException: Unable to cast object of type 'System.Int16' to type 'System.Boolean'.
at Microsoft.Data.SqlClient.SqlBuffer.get_Boolean()
at Microsoft.Data.SqlClient.SqlDataReader.GetBoolean(Int32 i)
at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator )
Then it must be some limitation of Entity Framework that I didn't know about. I found this page which seems to explain why it doesn't work. Using a [NotMapped] property is the only way to achieve what you are after.
@korchev
Thank you , sometimes it is what it is when you have to work with existing databases where you do not have any control over.
I'll let you know if I come across a better solution for this
Update :
Solution:
1: Create partial class of tableName.cs like e.g. tableName.custom.cs under Models.Context.
Add a new bool field to the model and decorate it with [NotMapped]:
[NotMapped]
public bool shortfield_tobool { get; set; }
2: Add a partial class to the controller of the table , tableNameController.Custom.cs.
Add the Read , Get and Update Methods to the partial class.