27

Better annotation of data for one decimal (18.2)

 3 years ago
source link: https://www.codesd.com/item/better-annotation-of-data-for-one-decimal-18-2.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Better annotation of data for one decimal (18.2)

advertisements

I have a column inside my sql server 2008 wih type of Decimal(18,2). But on entity framework what is the best data annotation validation I can apply to this property, inside my asp.net MVC web application ?


There is no explicit data annotation for a decimal so you need to use two separate ones to add constraints.

Two Decimal Points

[RegularExpression(@"^\d+\.\d{0,2}$")]

This regular expression will make sure that the property has at most two decimal places.

Max 18 digits

[Range(0, 9999999999999999.99)]

Assuming you aren't accepting any negative numbers. Otherwise, replace 0 with -9999999999999999.99.

Result

[RegularExpression(@"^\d+\.\d{0,2}$")]
[Range(0, 9999999999999999.99)]
public decimal Property { get; set; }

Related Articles

Would SQLite be better than basic data for recovery on time ranges, etc.?

I have read up on Core Data and SQLite 3 however I am not sure which would be best for me. I am getting a list of appointments from our API and will then need to store them. I will need to reference them based on date range, employee, customer etc. F

Annotation of data for the width of the column

I'm binding a collection of objects to a DevExpress GridControl, and using 15.1 Data Annotations to customise the look. However I'm struggling to find anything about setting column size of a property. Is this possible through annotations? Class with

save user data for one day (same day -> many user data)

I have an application where the user enters data in edittext and presses the save button. By pressing 'save' I save in a file the user data (in one column) and the current date (in the other column). Then , I press another button and make the plot (u

Regular expression for one decimal point with a maximum of 2 digits before the decimal point

I am trying to find a regular expression that works for a decimal with a max of 2 digits before the decimal point and 2 digits after the decimal point. The decimal point and decimal places are optional. So these values would be accepted : 90 5.4 45.2

Annotations of data for validation, at least one mandatory field?

If I have a search object with a list of fields, can I, using the System.ComponentModel.DataAnnotations namespace, set it up to validate that at least one of the fields in the search is not null or empty? i.e All the fields are optional but at least

Cron Quartz Schedule to shoot every week from a specific date for one year

I have a scenario, where I need to schedule a job using quartz which triggers every week from the date specified by the user and this should continue for exactly one year. After going through Cron Schedule examples, I think below cron expression migh

add specific days from a given date for one year

I have a start date like "2015-03-10". I want to add 1.25 days per month for the current year from this start date. For example, I have start date "2015-03-10" then for this year the number of days will be 12.50. (1.25 days for each mo

Annotated training data for the NER corpus

It is mentioned in the documentation of opennlp that we've to train our model with 15000 line for a good performance. now, I've to extract different entities from the document which means I've to add different tags for many tokens in the training dat

VB.Net VS 2008 validates textbox.text for one decimal place only

Repected Sir, I am restricting my textbox for numbers and decimal points only, i am able to get numbers and decimals only by the below function but not able to restrict making decimal points appearing twice on the input textbox. I guess If singleChar

How to better store the data for a chatbot?

I was looking on the internet for chatbots. It was only fun. But now, I love this subject so much that I want to develop my own chatbot. But the first thing is to look for a good way to manage the "brain" of my chatbot. I think that it's the bes

vim searches for one decimal but unbalances another number

When I use the vim to search a decimal(/0.03), like 0.03, in a text file, it will match not only the 0.03 but also the numbers such as 0403. What should I use to replace the search equation?The dot is being interpreted as "a single arbitary character

Which way is better to pass a large list of data from one activity to another activity - Android?

I need to pass a large list of data from one activity to another activity,which way is better? First way(for example): ArrayList<myModel> myList = new ArrayList<myModel>(); intent.putExtra("mylist", myList); Second way(for example) :

Combine two MySQL tables, use data in one for the headers in the combined table

I want to combine two MySQL tables, but use some data in one of them as new headers in the combined one. I have two tables, like this: A log of fruits we've eaten each day. id date fruit 5 2011-11-27 banana 4 2011-11-26 apple 3 2011-11-25 orange 2 20

Which collection to use for one or more types of data?

I have following table structure : table name : lookup cloumns : appname, wfname , wfdir , sessname so correspoding to a particular appname, wfname and wfdir , i have multiple sessname . app1,wf1,anydir,sess1 app1,wf1,anydir,sess2 app1,wf1,anydir,ses

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK