Note that there are some explanatory texts on larger screens.

plurals
  1. POCode First Fluent API validation not working
    primarykey
    data
    text
    <p>There is a class - it's a common class nothing special:</p> <pre><code>public class Trader{ public Guid UserId {get;set;} public int TraderId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string PhoneNumber { get; set; } public string Skype { get; set; } public string Photo { get; set; } public string Email { get; set; } public virtual User User { get; set; } } </code></pre> <p>Mapping:</p> <pre><code> public TraderMap() { this.ToTable("Trader", "General"); this.HasKey(a =&gt; a.TraderId); this.HasRequired(a =&gt; a.User).WithMany().HasForeignKey(a =&gt; a.UserId); Property(a =&gt; a.UserId).HasColumnName("UserID").IsRequired(); Property(a =&gt; a.TraderId).HasColumnName("TraderID").IsRequired(); Property(a =&gt; a.FirstName).HasMaxLength(50).IsRequired(); Property(a =&gt; a.LastName).HasMaxLength(50).IsRequired(); Property(a =&gt; a.PhoneNumber).HasMaxLength(25).IsRequired(); Property(a =&gt; a.Skype).HasMaxLength(50).IsOptional(); Property(a =&gt; a.Photo).HasMaxLength(100).IsOptional(); Property(a =&gt; a.Email).HasMaxLength(100).IsRequired(); } </code></pre> <p><strong>When I leave FirstName or other fields that have IsRequired() empty in the form (View) the validation do not kick in.</strong> It just runs into the error:</p> <blockquote> <p>Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.</p> </blockquote> <p>Unfortunately this error doesn't say too much. I was digging a little deeper but the only thing I was able to get was</p> <blockquote> <p>Invalid column name discriminator.</p> </blockquote> <p>I thought it would be some forgotten inheritance somewhere (for User class) but I haven't found anything suspicious.</p> <p>The problem is that when I use attributes in the Trader class everything works as supposed.</p> <pre><code> public class Trader{ public Guid UserId {get;set;} public int TraderId { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Required] public string PhoneNumber { get; set; } public string Skype { get; set; } public string Photo { get; set; } [Required] public string Email { get; set; } public virtual User User { get; set; } } </code></pre> <p>With attributes the validation works ok and @Html.ValidationMessageFor starts to display error messages and it doesn't allow to send NULL values.</p> <p>Do you have any suggestion what would be the problem with my mapping?</p> <p><strong>UPDATE 1</strong> In fact the attributes above are a possible solution to this problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload