hey I have the attribute fields as seen in the picture, I need to switch the type of status from string to enum for GraphQL. Unfortunately I have no clue how I can implement it.
Tried just to replace string with enum.
Related
Is there an annotation that allows me to say that the following property must have a numeric value and then I want to specify a range for that value?
[DataType.???]
[Range(1990, 2015)]
public string AnniversaryYear { get; set;}
There's a reason I need this to be a string.
check the use of Data Annotations Extensions that simply extends the data annotations that have into the framework, also look this article that show how to use them: Introducing Data Annotations Extensions
In my Mvc5 test project I have a model with a property like the following:
[Required]
[DisplayName("Codigo Cliente")]
public int ClientCode{ get; set; }
the default error message when the user enteres a letter of special character in the editor is:
The field Codigo Cliente must be a number.
How can I modify this? in this case I need to change the language, but in case that I wanted to show a more specific error what can I do?
I have tried with the DataType attribute but the Enum does not have a value that applys for this case (numbers)
Use Range:
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.rangeattribute.aspx
Or use IntegerOnly from Data Annotations Extensions
http://dataannotationsextensions.org/Integer/Create
The simplest way I found to solve this issue is use String with Range attribute in Data Annotation Model like specify below.
[Required]
[Range(0, int.MaxValue, ErrorMessage = "Codigo Cliente must be a positive or negative non-decimal number.")]
[DisplayName("Codigo Cliente")]
public string ClientCode { get; set; }
In Range attribute you can specify your custom Error Message.
For Interger use int.MaxValue , For double use double.MaxValue like so on.
I hope this will help you a lot.
If you want to specify a message you must use this
[Required(ErrorMessage = "your message")]
If you want to use a lang. based message is not that easy. You can use multiple resource file (for every language you need) and try a custom error binder that extends the DefaultModelBinder and make an override of the method BindModel(), there you can make your custom validation ad use your custom language message.
Given a string of categories, I need to split the string and insert each separate item as a new record using EF.
The following does not work since string cannot be converted to Tag:
Dim s = "Books, Novels, Magazines"
s.Split(", ").ToList.ForEach(Function(x) _rdsqlconn.Tags.Add(x))
I have googled and not found an answer to my dilemma. How can i split the string and insert each as a new tag record?
I'm guessing that your Tag class has a property to which the string value is to be assigned.
This should work:
Dim s = "Books, Novels, Magazines"
s.Split(", ").ToList.ForEach(Function(x) _rdsqlconn.Tags.Add(New Tag With { .Value = x });
Edit: Had to look up the VB.NET object initializer syntax. Make sure you replace "Value" with whatever property your need to use and also make sure you leave the period in front of the property name.
I am using Linq2Sql and want to bind an objects field (which is enum) to either a bit or a int type in the database. For example I want have a gender field in my model. I have already edited the DBML and changed the Type to point to my enum. I want to create Radio buttons (which I think I have figured out) for gender and dropdown lists for other areas using the same idea. My enum looks like this
public enum Gender
{
Male,
Female
}
Mapping between DbType 'int' and Type 'Project.Models.Gender' in Column 'Gender' of Type 'Candidate' is not supported.
Any ideas on how to do this mapping. Am I missing something on the enums.
If you have an int enum like this:
public enum Gender
{
Male = 0,
Female
}
and int column in your database, the next mapping should work without problem.
<Column Name="Gender" Type="global::Project.Models.Gender" DbType="Int NOT NULL"
CanBeNull="false" />
It is possible that global:: keyword is a key here. I had some problems with mapping integer data types to enums without it.
I've found that whereas
Type="System.Boolean" DbType="bit" CanBeNull="true"
works out that the type should be a nullable[of boolean], for an enum I have to specify the type as the nullable type..
Type="WhatNextEnum?" DbType="int" CanBeNull="true"
If you don't you'll get the "DBML1005: Mapping between DbType 'int' and Type 'WhatNextEnum' ... is not supported." error
i'm looking at some pages, and i've noticed that by default for ID in the routing for controller/action/ID is an integer and not a string.
How can I change it so it is a string?
Purely by creating an action like this:
Public Function MyAction(ByVal id as String) as ActionResult
The framework converts the url MyController/MyAction/SomeId for you. Normally it would convert the last section into an integer as that is how your method is defined, there's nothing to stop you from saying that it is a string and so no conversion is needed.