efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Metadata, Precision, Scale and Formulas in Calculate Fields

Open JuanIrigoyen opened this issue 10 years ago • 3 comments

I 'm adapting my model to use EF7 , I need to upload the metadata of each entity and each field for different tasks that do not use EF directly, I managed to solve most through IEntityType interface and Sql Server extension, but there are three that I can not get.

They are: Precision, Scale in the numerical values ​​and formulas for calculated fields​​.

There would be some way using EF to obtain these values. I know I can get them directly from the database but I would like to load them as I do with others.

Thank you.

JuanIrigoyen avatar Jun 08 '16 20:06 JuanIrigoyen

@JuanIrigoyen EF metadata does not currently store precision or scale since these are never used in the EF code. Default or computed values can be accessed using metadata extensions, such as property.SqlServer().ComputedColumnSql where "property" is an IProperty from the model.

ajcvickers avatar Jun 10 '16 20:06 ajcvickers

I think EF 7 should return precision & scale as it does with attributes like maxlenght as part of the metadata fields, this can be very useful for example to set the masks of some controls. Great work by the facility to access metadata compared to version 6, thank you very much for your reply

JuanIrigoyen avatar Jun 14 '16 23:06 JuanIrigoyen

Max length is exposed in EF metadata if it is set when building the metadata, but it is not inferred into the metadata based on store type. For example, setting the store type to varchar(200) will not result in a max length in EF metadata of 200. Another way to think of this is that max length may be used as an input to type mapping, but the type mapping itself does not affect core metadata.

Given this, if metadata had precision and scale, then it would only be included in metadata if set when building the model. It would not be inferred from the store type. But EF does not do this, and so it is not needed in the model.

If you have additional metadata about your model that is not used by EF but which you wish to reference, then you can always store that metadata as annotations on the property, type, etc., and then refer to it later when doing things like creating masks.

ajcvickers avatar Jun 15 '16 20:06 ajcvickers