Hello I am using tinyint(1) in MySQL DB and use Mygeneration to generate NHibernate Contribute 0.8.4 table mapping.
Here is the mapping column of nhibernate for tinyint(1)
...
<property column="getNews" type="Byte" name="GetNews" />
...
After I have successful generate the source code files and nhibernate mapping files then I tried to build the generated code. It said error of "value.Length" because byte in .net do not have "Length" property. So I comment out the lines of length checking then it looks like
...
public byte GetNews
{
get { return m_getnews; }
set
{
// if( value.Length > 0)
// throw new ArgumentOutOfRangeException("Invalid value for GetNews", value, value.ToString());
m_isChanged |= (m_getnews != value); m_getnews = value;
}
}
...
I try to run the code using
...
string mappingAssembly = "Aibiz.EmailReminderService.Data";
// Create NHibernate configuration
Configuration cfg = new Configuration();
// Add mapping assembly to configuration
// Mapping assembly has the Entities and mappings
cfg.AddAssembly(mappingAssembly);
// Create a session factory
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = null;
try
{
// Create a sesson
session = factory.OpenSession();
ICriteria criteria = session.CreateCriteria(typeof(Hostings));
SimpleExpression expression = Expression.Ge("HostStop","2004-09-10");
criteria.Add(expression);
IList hostings = criteria.List();//session.Find("from Hostings where HostStop like ?", "2005-09-10", NHibernateUtil.String);
foreach (Domains domain in hostings)
{
log.Debug(domain.Domainid);
}
}
catch (Exception ex)
{
log.Error(ex);
}
finally
{
session.Close();
}
...
Then error occurs at line "cfg.AddAssembly(mappingAssembly);" and the stack trace says
...
2005-06-17 11:44:00,885 [1940] DEBUG NHibernate.Cfg.Binder [] <> - Mapped property: GetNews -> getNews, type: Byte
2005-06-17 11:44:00,885 [1940] INFO NHibernate.Cfg.Configuration [] <> - Found mapping documents in assembly: Aibiz.EmailReminderService.Data.Hostings.hbm.xml
2005-06-17 11:44:04,666 [1940] ERROR NHibernate.Cfg.Configuration [] <> - Could not configure datastore from input stream
Exception: System.Xml.Schema.XmlSchemaException
Message: The 'length' attribute has an invalid value according to its data type. An error occurred at , (22, 53).
Source: NHibernate
at NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArgs args)
at System.Xml.Schema.ValidationEventHandler.Invoke(Object sender, ValidationEventArgs e)
at System.Xml.Schema.Validator.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
at System.Xml.Schema.Validator.SendValidationEvent(XmlSchemaException e)
at System.Xml.Schema.Validator.ProcessElement()
at System.Xml.Schema.Validator.Validate()
at System.Xml.Schema.Validator.Validate(ValidationType valType)
at System.Xml.XmlValidatingReader.ReadWithCollectTextToken()
at System.Xml.XmlValidatingReader.Read()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)
I think the problem is data length mapping checking between xml and mysql data type because "byte" do not have "Length". But how to fix this?
|