0

I am new to NHibernate and MVC too.

I have a model class which contains properties like

public class RegisterViewModel
{

    [Required]
    [Display(Name="Full Name")]
    public string Name { get; set; }

    [Required]
    [Display(Name = "Email Id")]
    public string EailID { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 1)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

I have created xml mapping file for this model is like below.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   auto-import="true" assembly="EventMgnt" namespace="EventMgnt.Models">
  <class name="EventMgnt.Models.RegisterViewModel" table="tblUser" dynamic-update="true" >
    <cache usage="read-write"/>
    <id name="Id" column="Id" type="int">
      <generator class="native" />
    </id>
    <property name="Name" />
    <property name="EmailID" />
    <property name="Password" />
    <property name="ConfirmPassword" />
  </class>
</hibernate-mapping>

And i am getting Could not compile the mapping document error. Now I have few questions that,

  1. Is it neccessary to write all properties which are available in model class in Nhibernate xml mapping file?
  2. What if i do not have 1 column in database of confirm password?

Any help would be grateful.

2
  • You should take a look at "3 layer architecture". Its not a good approach to use your ViewModel as entity. The name already states it, it is for views, not for data persistence. And as small hint: you can use FluentNhibernate to map your entities. Its much easier to handle than .hbm files. Commented Jul 17, 2017 at 10:44
  • This is nice suggestion, helped me for my another task. Thank you. @Rabban Commented Jul 19, 2017 at 4:46

1 Answer 1

2
  1. No not required
  2. You need to add database column matching properties only. You can ignore confirm password property Most probably this error is related to NHibernate mapping assembly or namespace
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.