0

am trying to implement fluent nhibernate in MVC project...there were no build errors... but when i run the project i get this exception

System.Xml.Schema.XmlSchemaValidationException: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.

have no idea what am doing wrong here... the following is the code for opening session factory...

Private Function CreateSessionFactory() As ISessionFactory
    Dim sessionFactoryObject As ISessionFactory
    sessionFactoryObject = Fluently.Configure().Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005.ConnectionString("Data Source=.\sqlexpress;Initial Catalog=Designs;User ID=sa;Password=root")).Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap))).BuildSessionFactory()
    Return sessionFactoryObject
End Function

this is really driving me nuts....thanks in advance...:)

update-the mappings the design table map

Public Class DesignMap
Inherits ClassMap(Of Design)

Public Sub DesignMap()
    Table("DesignList")
    Id(Function(x) x.DesignId)
    Map(Function(x) x.DesignType)
    References(Function(x) x.Designer, "DesignerId")
End Sub
End Class

the designer table map

Public Class DesignerMap
Inherits ClassMap(Of Designer)
Public Sub DesignerMap()
    Table("DesignerList")
    Id(Function(x) x.DesignerId)
    Map(Function(x) x.DesignerName)
    Map(Function(x) x.DesignerCompany)
    HasMany(Function(x) x.DesignersDesigns)
End Sub
End Class

new edit-- the entity property looks like this

    Public Overridable Property Name() As String
     Get
        Return _name
     End Get
     Protected Set(ByVal value As String)
        _name = value
     End Set
    End Property

am i going the right way..?

3
  • 1
    That error means that there is something wrong with the mappings. Can you post your mapping (DesignMap) please? Commented Jan 29, 2010 at 9:34
  • That specific error is most common when you're missing an id. Show your mappings please. Commented Jan 29, 2010 at 9:47
  • am totally lost here..pls check the mapppings... Commented Jan 29, 2010 at 11:10

3 Answers 3

1

I'm not quite sure as the mappings seem ok. I can see one error tough, you have only mapped one of your classes:

.Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap)))

That should not cause this type of error tough. If you add both your mappings and call the method .ExportTo(@"C:\your\export\path") you will get the actual xml mappings. This way it's easier to see the error. You can do that like this:

.Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap)).Add(GetType(DesignerMap
).ExportTo(@"C:\your\export\path"))

You can also use the method AddFromAssemblyOf (or some other. There is a few choices) if you don't want to add the mappings one by one.

Try exporting the mappings and see if you can find any error. Or you can post the xml mappings and someone else might find something.

Sign up to request clarification or add additional context in comments.

1 Comment

Did you get the xml mappings? The error is in there somewhere. And its usually easier to find it by looking at the xml.
0

There are several things that can cause this. When using automappings, you will get this if you incorrectly specify the assemblies and namespaces to look in. Other things (more likely in your case) that could cause it, are entity properties that aren't marked as public virtual, having an entity constructor with arguments, but neglecting to make a default constructor, or inheriting your entities from a base class.

I would probably first check to make sure all of your entity properties are "public virtual".

1 Comment

sorry for the late response...was out for the weekend...i tried the vritual property...still no improvement....:(
0

found the problem...the constructor for the map was wrong...it should be like this...

Public Class DesignMap
 Inherits ClassMap(Of Design)

 Public Sub New()
  Table("DesignList")
  Id(Function(x) x.DesignId)
  Map(Function(x) x.DesignType)
  References(Function(x) x.Designer, "DesignerId")
End Sub
End Class

problems of working in both C# and vb.net at the same time i guess..!!

and "Matthew Talbert" was correct...making all the properties Overrideable is important..

thanks guys...:)

1 Comment

Hehe, so obvious. Sorry I didn't see that. Haven't worked with vb for years.

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.