data-annotations

Entity Framework Core Data Annotation Database Generated Values

大兔子大兔子 提交于 2019-12-11 04:58:18
问题 The Entity Framework Core documentation for Generated Properties makes it seem like Data Annotations can be used for generated code first "timestamp" properties such as created/updated on as a DateTime type. When trying to use the following data annotations along with code first migrations: public class Foo { // some properties [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public DateTime Created { get; set; } // more properties } I receive the following error when attempting to

Index already exists error in EF 4.3 Code First with Data Annotations

我的未来我决定 提交于 2019-12-11 04:18:39
问题 I'm trying to create a billing database with Entity Framework 4.3 using Code First with Data Annotations, and I'm getting an error every time I try to create my database. Here are the objects that I'm dealing with: public class ClientBase { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ClientID { get; set; } [Required] public string ClientName { get; set; } [Required] public bool IsActive { get; set; } [Required] public string ClientContactName { get; set; } [Required]

Validation Context is always NULL?

依然范特西╮ 提交于 2019-12-11 04:09:29
问题 I have custom validation attribute such as this: public class MyCustomAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if ((int)value == 100) { // do some checking to validate & return ValidationResult accordingly } else return ValidationResult.Success; } } In usage like this: [DisplayName("My Custom Property")] [MyCustom(ErrorMessage = "ERROR!!!")] public int? MyCustomProperty { get; set; } My question is: why

ASP.NET MVC 2 - Handling files in an edit action; Or, is it possible to create an 'Optional' data annotation which would skip over other attributes?

主宰稳场 提交于 2019-12-11 03:22:20
问题 I've run into a bit of a design issue, and I'm curious if anyone else has run into something similar. I have a fairly complex model which I have an Edit action method for. Each individual entity has two images associated with it, along with other, more mundane data. These images are [Required] upon creation. When editing an entity, however, these images already exist, since, again, they were required upon creation. Thus, I don't need to mark them as required. Adding a bit of a monkey wrench

Entity Framework 4, TPH (Table Per Hierarchy) and annotation

泪湿孤枕 提交于 2019-12-11 02:56:23
问题 I currently try to migrate an application of mine from datasets to EF4. So I have an existing database. One of the tables is mapped to 2 classes, depending of the value of a column. So I am in a TBH schema with an existing table and an existing discriminator. Is there a way to discribe this using annotations ? thanks 回答1: No. TPH discriminator can be controlled only through Fluent-API. 来源: https://stackoverflow.com/questions/10014410/entity-framework-4-tph-table-per-hierarchy-and-annotation

EF 4.4 InverseProperty does not quite inverse

烈酒焚心 提交于 2019-12-11 02:25:03
问题 This might really be something obvious but I'm not sure why my InverseProperty annotation does not work the other way. I have this 2 classes (simplified): public class Cluster { [Key] public int ClusterId { get; set; } [Required] [MaxLength(80, ErrorMessage = "DimensionCluster Name cannot be more than 80 characters in length.")] [Display(Name = "DimensionCluster Name")] public string ClusterName { get; set; } [InverseProperty("DimensionCluster")] public virtual IEnumerable<Dimension>

Ninject is not working in custom validation attribubte in ASP.NET MVC

丶灬走出姿态 提交于 2019-12-11 01:57:26
问题 This question is the consequence of this question. I am developing an ASP.NET MVC Web Application. In my project I am doing remote validation using data annotation to my view model class. I know default remote attribute does not support server validation. I can validate it again in action method. But I do not want to do that it is violating separation of concerns. So I tried to create custom server client remote validation attribute. I found a code online and I used it. But it is giving me

Validate textbox to accept only valid datetime value using DataAnnotations in mvc3

安稳与你 提交于 2019-12-11 01:54:56
问题 I want to validate a textbox to accept datetime value using DataAnnotations in MVC3. But I don't have any idea how to do it. Given below is what I'm trying to accomplish my requirement and it's not working. [DataType(DataType.DateTime, ErrorMessage = "Invalid Datetime")] [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}")] [Display(Name = "Start Datetime")] public DateTime? StartDateTime { get; set; } As When I click on submit button after filling corrupted data first problem is that

NerdDinner form validation DataAnnotations ERROR in MVC2 when a form field is left blank

只愿长相守 提交于 2019-12-11 01:09:18
问题 Platform: Windows 7 Ultimate IDE: Visual Studio 2010 Ultimate Web Environment: ASP.NET MVC 2 Database: SQL Server 2008 R2 Express Data Access: Entity Framework 4 Form Validation: DataAnnotations Sample App: NerdDinner from Wrox Pro ASP.NET MVC 2 Book: Wrox Professional MVC 2 Problem with Chapter 1 - Section: "Integrating Validation and Business Rule Logic with Model Classes" (pages 33 to 35) ERROR Synopsis: NerdDinner form validation ERROR with DataAnnotations and db nulls. DataAnnotations in

A general validation attribute for checking uniqueness in a linq to sql data context

强颜欢笑 提交于 2019-12-11 00:25:12
问题 I've been programming asp.net for, oh, a couple of days now. Here's a question I can't even begin to figure out for myself. I hope it's obvious from the code what I want to accomplish, and I have, but it's not pretty. Furthermore I'd like to use it on whatever table, whatever field, i.e. check the uniqueness of a value against a table and field I specify, passing it all into the attribute constructor. public class UniqueEmailAttribute : ValidationAttribute { public UniqueEmailAttribute() { }