XmlSchemaException:枚举约束失败

时间:2013-12-12 12:09:49

标签: c# java hibernate nhibernate

我是NHibernate的新手,我正在尝试将ORM用于Sql Server 2012 我的代码是

GazelleInfo.cs

 namespace WCG.Data.EntityObjects
    {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.ComponentModel.DataAnnotations;
        using System.Data.SqlTypes;

         ///<summary>
            ///Class to access Gazelle Info Table
            ///</summary>
        public class GazelleInfo
        {
            public virtual int ID { get; set; }

            [Required(ErrorMessage = "Specialty Name is required.")]
            [Display(Name = "Specialty Name")]
            public virtual string SpecialtyName { get; set; }

            [Display(Name = "Specialty Name Active")]
            public virtual bool SpecialtyNameActive { get; set; }

            [Display(Name = "Preferred Language")]
            public virtual string PreferredLanguage { get; set; }

            [Display(Name = "Preferred Language Active")]
            public virtual bool PreferredLanguageActive { get; set; }

            [Display(Name = "Race")]
            public virtual string Race { get; set; }

            [Display(Name = "Race Active")]
            public virtual bool RaceActive { get; set; }

            [Display(Name = "Ethnicity")]
            public virtual string Ethnicity { get; set; }

            [Display(Name = "Ethnicity Active")]
            public virtual bool EthnicityActive { get; set; }

            [Display(Name = "Holiday Name")]
            public virtual string HolidayName { get; set; }

            [Display(Name = "Holiday Name Active")]
            public virtual bool HolidayNameActive { get; set; }


        }
    }

GazelleInfo.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data" namespace="WCG.Data.EntityObjects">
  <class name="GazelleInfo" table="GazelleInfo">
    <id name="Id" column="Id" type="System.Int32">
      <generator class="identity" />
    </id>
    <property name="SpecialtyName" column="SpecialtyName" type="System.String" />
    <property name="SpecialtyNameActive" column="SpecialtyNameActive" type="System.Boolean" insert="true" update="true"/>
    <property name="PreferredLanguage" column="PreferredLanguage" type="System.String" insert="true" update="true"/>
    <property name="PreferredLanguageActive" column="PreferredLanguageActive" type="System.Boolean" insert="true" update="true"/>
    <property name="Race" column="Race" type="System.String" insert="true" update="true"/>
    <property name="RaceActive" column="RaceActive" type="System.Boolean" insert="true" update="true"/>
    <property name="Ethnicity" column="Ethnicity" type="System.String" insert="true" update="true"/>
    <property name="EthnicityActive" column="EthnicityActive" type="System.Boolean" insert="true" update="true"/>
    <property name="HolidayName" column="HolidayName" type="System.String" insert="true" update="false"/>
    <property name="HolidayNameActive" column="HolidayNameActive" type="System.Boolean" insert="true" update="true"/>
  </class>
</hibernate-mapping>

的hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="NHibernate.Test">
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=KNS009-PC;Initial Catalog=WomensCare;Integrated Security=True</property>
    <property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="current_session_context_class">NHibernate.Context.ThreadLocalSessionContext</property>
    <property name="hbm.ddl.auto">update</property>
    <!--<property name="Show_Sql">true</property>-->
  </session-factory>
</hibernate-configuration>

Configure.cs

namespace WCG.Data.DataAccessLayer.Hibernate
{
    using NHibernate.Cfg;
    using System.Reflection;
    using System.IO;

    public class Configure
    {
        public Configure()
        {

        }

        public static Configuration GetConfiguration(string configPath)
        {
            var directoryName = configPath;

            Configuration cfg = new Configuration().Configure(directoryName + @"\Hibernate.cfg.xml")
                    .AddFile(directoryName + @"\User.hbm.xml")
                    .AddFile(directoryName + @"\Role.hbm.xml")
                    .AddFile(directoryName + @"\RolePrivilege.hbm.xml")
                    .AddFile(directoryName + @"\Privilege.hbm.xml")
                    .AddFile(directoryName + @"\Patient.hbm.xml")
                    .AddFile(directoryName + @"\Report.hbm.xml")
                    .AddFile(directoryName + @"\CommentMaster.hbm.xml")
                    .AddFile(directoryName + @"\AuditEntry.hbm.xml")
                    .AddFile(directoryName + @"\ReportHistory.hbm.xml")
                    .AddFile(directoryName + @"\ReportStatus.hbm.xml")
                    .AddFile(directoryName + @"\Emailtemplates.hbn.xml")
                    .AddFile(directoryName + @"\DemographicInfo.hbm.xml")
                    .AddFile(directoryName + @"\InsuranceInfo.hbm.xml")
                    .AddFile(directoryName + @"\MaritalStatus.hbm.xml")
                    .AddFile(directoryName + @"\MedicalHistory.hbm.xml")
                    .AddFile(directoryName + @"\PatientRelationship.hbm.xml")
                    .AddFile(directoryName + @"\lablabel.hbm.xml")
                    .AddFile(directoryName + @"\CompanyInfo.hbm.xml")
                    .AddFile(directoryName + @"\MensurationHistory.hbm.xml")
                    .AddFile(directoryName + @"\PastPregnancies.hbm.xml")
                    .AddFile(directoryName + @"\PastMedicalHistoryInfo.hbm.xml")
                    .AddFile(directoryName + @"\PastMedicalHistory.hbm.xml")
                    .AddFile(directoryName + @"\HospitalizationDetails.hbm.xml")
                    .AddFile(directoryName + @"\DrugDetails.hbm.xml")
                    .AddFile(directoryName + @"\PastMedicalHistoryComments.hbm.xml")
                    .AddFile(directoryName + @"\GeneticScreening.hbm.xml")
                    .AddFile(directoryName + @"\GeneticScreeningInfo.hbm.xml")
                    .AddFile(directoryName + @"\GeneticScreeningComments.hbm.xml")
                    .AddFile(directoryName + @"\InfectionHistory.hbm.xml")
                    .AddFile(directoryName + @"\InfectionHistoryComments.hbm.xml")
                    .AddFile(directoryName + @"\InfectionHistoryInfo.hbm.xml")
                    .AddFile(directoryName + @"\MedicationAgents.hbm.xml")
                    .AddFile(directoryName + @"\CompanyPlanInfo.hbm.xml")
                    .AddFile(directoryName + @"\SyncKareo.hbm.xml")
                    .AddFile(directoryName + @"\NonHospitalizationDetails.hbm.xml")
                    .AddFile(directoryName + @"\PayerScenario.hbm.xml")
                    .AddFile(directoryName + @"\AdminDemographicInfo.hbm.xml")
                    .AddFile(directoryName + @"\AdminInsuranceInfo.hbm.xml")
                    .AddFile(directoryName + @"\SoapNotes.hbm.xml")
                    .AddFile(directoryName + @"\CurrentMedicationInfo.hbm.xml")
                    .AddFile(directoryName + @"\CurrentMedication.hbm.xml")
                    .AddFile(directoryName + @"\Allergies.hbm.xml")
                    .AddFile(directoryName + @"\AllergiesInfo.hbm.xml")
                    .AddFile(directoryName + @"\Pharmacy.hbm.xml")
                    .AddFile(directoryName + @"\PatientPharmacy.hbm.xml")
                    .AddFile(directoryName + @"\DemographicInfoHistory.hbm.xml")
                    .AddFile(directoryName + @"\PatientsHistory.hbm.xml")
                    .AddFile(directoryName + @"\UserHistory.hbm.xml")
                    .AddFile(directoryName + @"\InsuranceInfoHistory.hbm.xml")
                    .AddFile(directoryName + @"\MainPatientHistory.hbm.xml")
                    .AddFile(directoryName + @"\HistoryMensurationHistory.hbm.xml")
                    .AddFile(directoryName + @"\HistoryInfectionHistoryComments.hbm.xml")
                    .AddFile(directoryName + @"\HistoryGeneticScreeningComments.hbm.xml")
                    .AddFile(directoryName + @"\HistoryPastMedicalHistoryComments.hbm.xml")
                    .AddFile(directoryName + @"\HistoryInfectionHistory.hbm.xml")
                    .AddFile(directoryName + @"\HistoryDrugDetails.hbm.xml")
                    .AddFile(directoryName + @"\HistoryHospitalizationDetails.hbm.xml")
                    .AddFile(directoryName + @"\HistoryNonHospitalizationDetails.hbm.xml")
                    .AddFile(directoryName + @"\HistoryAllergies.hbm.xml")
                    .AddFile(directoryName + @"\HistoryCurrentMedication.hbm.xml")
                    .AddFile(directoryName + @"\HistoryPastPregnancies.hbm.xml")
                    .AddFile(directoryName + @"\HistoryGeneticScreening.hbm.xml")
                    .AddFile(directoryName + @"\HistoryMedicationAgents.hbm.xml")
                    .AddFile(directoryName + @"\MainMedicalHistory.hbm.xml")
                    .AddFile(directoryName + @"\HistoryPastMedicalHistory.hbm.xml")
                    .AddFile(directoryName + @"\PaymentMethod.hbm.xml")
                    .AddFile(directoryName + @"\FrontDeskPaymentHistory.hbm.xml")
                    .AddFile(directoryName + @"\FinancialInfo.hbm.xml")
                    .AddFile(directoryName + @"\ObPatients.hbm.xml")
                    .AddFile(directoryName + @"\Locations.hbm.xml")
                    .AddFile(directoryName + @"\LocationDetails.hbm.xml")
                    .AddFile(directoryName + @"\LocationSpecialDetails.hbm.xml")
                    .AddFile(directoryName + @"\Holidays.hbm.xml")
                    .AddFile(directoryName + @"\VisitType.hbm.xml")
                    .AddFile(directoryName + @"\CalendarDisplayRange.hbm.xml")
                    .AddFile(directoryName + @"\CalendarStatus.hbm.xml")
                    .AddFile(directoryName + @"\Appointments.hbm.xml")
                    .AddFile(directoryName + @"\SchedulingProfile.hbm.xml")
                    .AddFile(directoryName + @"\SchedulingProfileDetails.hbm.xml")
                    .AddFile(directoryName + @"\ReplyEmail.hbm.xml")
                    .AddFile(directoryName + @"\OnlineApptWindow.hbm.xml")
                    .AddFile(directoryName + @"\MultiAppointmentsColor.hbm.xml")
                    .AddFile(directoryName + @"\FaxHistory.hbm.xml")
                    .AddFile(directoryName + @"\GazelleInfo.hbm.xml");
            return cfg;
        }


    }
}

我得到了一些其他例外

查看错误信息

    [XmlSchemaException: The Enumeration constraint failed.]

    [XmlSchemaValidationException: The 'name' attribute is invalid - The value 'hbm.ddl.auto' is invalid according to its datatype 'String' - The Enumeration constraint failed.]

    [HibernateConfigException: An exception occurred parsing configuration :The 'name' attribute is invalid - The value 'hbm.ddl.auto' is invalid according to its datatype 'String' - The Enumeration constraint failed.]
       NHibernate.Cfg.XmlSchemas.ConfigSettingsValidationEventHandler(Object sender, ValidationEventArgs e) +137
       System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity) +91
       System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String[] args, Exception innerException) +87
       System.Xml.Schema.XmlSchemaValidator.CheckAttributeValue(Object value, SchemaAttDef attdef) +318
       System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String lName, String ns, XmlValueGetter attributeValueGetter, String attributeStringValue, XmlSchemaInfo schemaInfo) +1166
       System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String localName, String namespaceUri, XmlValueGetter attributeValue, XmlSchemaInfo schemaInfo) +28
       System.Xml.XsdValidatingReader.ValidateAttributes() +144
       System.Xml.XsdValidatingReader.ProcessElementEvent() +620
       System.Xml.XsdValidatingReader.ProcessReaderEvent() +56
       System.Xml.XsdValidatingReader.Read() +48
       System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space) +523
       System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space) +19
       System.Xml.XPath.XPathDocument..ctor(XmlReader reader) +6
       NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting) +186
       NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader) +39
       NHibernate.Cfg.Configuration.Configure(XmlReader textReader) +304
       NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig) +142
       NHibernate.Cfg.Configuration.Configure(String fileName) +44
       WCG.Data.DataAccessLayer.Hibernate.Configure.GetConfiguration(String configPath) in c:\Users\Admin\Desktop\womenscare\womencare\Data\DataAccessLayer\Configure.cs:18
       Web.Global.Application_Start() in 

c:\Users\Admin\Desktop\womenscare\womencare\Web\Global.asax.cs:40

1 个答案:

答案 0 :(得分:1)

变化:

<property name="hbm.ddl.auto">update</property>

<property name="hbm2ddl.auto">update</property>

尝试引用程序集

  <mapping assembly="assemblyName"/>

设置所有映射文件嵌入式资源