Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET NHibernate
I have this class:
    public class AttachmentLocation
    {
        #region properties
        
        public virtual Guid UserId { get; set; }
     
        public virtual Guid LocationId { get; set; }
        
        public virtual long IndexInLocation { get; set; }
        
        #endregion
    
        #region contained foreign objects
        
        public virtual Attachment Attachment { get; set; }
        
        #endregion
    
    
        #region Methods need to override for CompositeId
    
        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            var t = obj as AttachmentLocation;
            if (t == null)
                return false;
            if (UserId == t.UserId && LocationId == t.LocationId && Attachment.Id == t.Attachment.Id)
                return true;
            return false;
        }
    
        public override int GetHashCode()
        {
            return (UserId + "|" + LocationId + "|" + Attachment.Id).GetHashCode();
        }
    
        #endregion
        
    }
 
I have this Fluent Mapping:
 
    public class AttachmentLocaionMap : ClassMap<attachmentlocation>
    {
        public AttachmentLocaionMap()
        {
            Table("Metadata_AttachmentLocation");
            CompositeId()
                .KeyReference(x => x.UserId, "UserId")
                .KeyReference(x => x.Attachment.Id, "AttachmentId")
                .KeyReference(x => x.LocationId, "LocationId");
            Map(x => x.IndexInLocation).Not.Nullable();
            Map(x => x.LocationId).Not.Nullable();
    
            HasOne(x => x.Attachment);
        }
    }</attachmentlocation>
 
which I register:
 
    SessionFactory = Fluently.Configure(configuration).Mappings(m =>
    {
        m.FluentMappings.AddFromAssemblyOf<attachmentlocaionmap>();           
        m.FluentMappings.AddFromAssemblyOf<frienddetailsmap>();
    }).BuildSessionFactory();</frienddetailsmap></attachmentlocaionmap>
 
I get this runtime error:
> An association from the table Metadata_AttachmentLocation refers to an
> unmapped class: System.Guid
> 
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code. 
> 
> Exception Details: NHibernate.MappingException: An association from
> the table Metadata_AttachmentLocation refers to an unmapped class:
> System.Guid
> 
> Source Error: 
> 
> 
> Line 19:  Line 20:  Line 21:             SessionFactory =
> Fluently.Configure(configuration).Mappings(m => Line 22:             {
> Line 23:                
> m.FluentMappings.AddFromAssemblyOf<attachmentlocaionmap>();
> 
> Source File: C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Infrastructure\Dal\Adapters\NHibernateAdapter\NHibernateHelper.cs
> Line: 21 
> 
> Stack Trace: 
> 
> 
> [MappingException: An association from the table
> Metadata_AttachmentLocation refers to an unmapped class: System.Guid] 
> NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:342   
> NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table,
> ISet done) in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:1169   
> NHibernate.Cfg.Configuration.SecondPassCompile() in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:1120   
> NHibernate.Cfg.Configuration.BuildSessionFactory() in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:1249   
> FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in
> d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:227
> 
> [FluentConfigurationException: An invalid or incomplete configuration
> was used while creating a SessionFactory. Check PotentialReasons
> collection, and InnerException for more detail.
> 
>   * Database was not configured through Database method. ]   
> FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in
> d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:232
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateHelper.OpenSession()
> in C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Infrastructure\Dal\Adapters\NHibernateAdapter\NHibernateHelper.cs:21
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateHelper.GetSession()
> in C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Infrastructure\Dal\Adapters\NHibernateAdapter\NHibernateHelper.cs:36
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateDal`1..ctor()
> in C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Infrastructure\Dal\Adapters\NHibernateAdapter\NHibernateDal.cs:16
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateDalFactory.GetDal()
> in C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Infrastructure\Dal\Adapters\NHibernateAdapter\NHibernateDalFactory.cs:17
> Ugi.Server.Sources.Logic.SourcesService..ctor() in
> C:\Users\elad\Documents\Visual Studio
> 2010\Projects\SVN\UGI\Ugi\Server\Sources\Logic\SourcesService.cs:36   
> BuildUp_Ugi.Server.Sources.Logic.SourcesService(IBuilderContext ) +153
> Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext
> context) in
> c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:37
> Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
> context) in
> c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:43
> Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
> context) in
> c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:110
> Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
> existing, String name, IEnumerable`1 resolverOverrides) in
> c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:512
> 
> [ResolutionFailedException: Resolution of the dependency failed, type
> = "Ugi.Common.Model.Sources.ISourcesService", name = "(none)". Exception occurred while: Calling constructor
> Ugi.Server.Sources.Logic.SourcesService(). Exception is:
> FluentConfigurationException - An invalid or incomplete configuration
> was used while creating a SessionFactory. Check PotentialReasons
> collection, and InnerException for more detail.
> 
>   * Database was not configured through Database method.
</attachmentlocaionmap>
 
How can I fix that?
 
TIA
Posted 26-Nov-11 0:30am
Edited 26-Nov-11 0:36am
Mehdi Gholam253.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I also have similar problem, I am very much new to this hibernate & fluent hibernate.
 
My table schema is like below
CREATE TABLE [dbo].[MyChildImmunisations](
	[Child_id] [int] NOT NULL,
	[Schedule_id] [int] NOT NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_MyChildImmunisations] PRIMARY KEY CLUSTERED 
(
	[Child_id] ASC,
	[Schedule_id] ASC
))
 
My mapping class code like below.
 
protected MyChildImmunisationMap(string tableName)
        {
            Table(tableName);
 
            CompositeId()
                .KeyReference(ci => ci.Child.Id, "Child_id")
                .KeyReference(ci => ci.Schedule.Id, "Schedule_Id");
 
            Map(ci => ci.Status).CustomType<childimmunisationstatus>();
        }</childimmunisationstatus>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 25 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100