I have a Class generated with POCO T4 Template, I'm using this code to adding to the Partial Class some DataAnnotation.
I would like to know:
How to hide the field OptionId (in the DB is a Primary Key with IDENTITY) so the User does not need input this value in the View (but with setting in the model).
Also I would like to know if [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
is REQUIRED or EF with POCO will create automatically the new ID (is IDENTITY)
namespace MyProject.Models
{
[MetadataType(typeof(ReOptionMetadata))]
public partial class ReOption
{
private class ReOptionMetadata
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[HiddenInput(DisplayValue = false)] // Is it correct?
public int OptionId { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Value { get; set; }
[Required]
public string Description { get; set; }
[Required]
public string NoteInternal { get; set; }
}
}
}
@Html.HiddenFieldFor(model => model.ColumnWhichContainsTheId)
吗?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.