表X中的关联引用了未映射的类:System.Guid [英] An association from the table X refers to an unmapped class: System.Guid

查看:47
本文介绍了表X中的关联引用了未映射的类:System.Guid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个课程:

公共类AttachmentLocation 
{
#region properties

public virtual Guid UserId {得到;组; }

public virtual Guid LocationId {get;组; }

public virtual long IndexInLocation {get;组; }

#endregion

#region包含外来对象

public virtual Attachment Attachment {get;组; }

#endregion


#region方法需要覆盖CompositeId

公共覆盖bool Equals(object obj)
{
if(obj == null)
返回false;
var t = obj as AttachmentLocation;
if(t == null)
返回false;
if(UserId == t.UserId&& LocationId == t.LocationId&&& Attachment.Id == t.Attachment.Id)
return true;
返回false;
}

公共覆盖int GetHashCode()
{
return(UserId +|+ LocationId +|+ Attachment.Id).GetHashCode() ;
}

#endregion

}





我有这个Fluent地图:



公共类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>





我注册:



 SessionFactory = Fluently.Configure(配置).Mappings(m => 
{
m.FluentMappings.AddFromAssemblyOf< attachmentlocaionmap>();
m.FluentMappings.AddFromAssemblyOf< frienddetailsmap> ();
})。BuildSessionFactory();< / frienddetailsmap>< / attachmentlocaionmap>





我收到此运行时错误:

> ;表Metadata_AttachmentLocation中的关联是指
> unmapped类:System.Guid
>
>说明:执行
>期间发生未处理的异常当前的网络请求。请查看堆栈跟踪以获取更多
>有关错误的信息以及它在代码中的起源。
>
>异常详细信息:NHibernate.MappingException:来自
>的关联表Metadata_AttachmentLocation是指未映射的类:
> System.Guid
>
>来源错误:
>
>
>第19行:第20行:第21行:SessionFactory =
> Fluently.Configure(配置).Mappings(m =>第22行:{
>第23行:
> m.FluentMappings.AddFromAssemblyOf< attachmentlocaionmap>();
>
>源文件:C:\ Users \ elad \Documents\Visual Studio
> 2010 \Projects \SVN \UGI \ Ugi \ Infrastructure * \\ Dal \ Adapters \NHibernateAdapter \NHibernateHelper.cs
>行:21
>
>堆栈追踪:
>
>
> ; [MappingException:来自表
> Metadata_AttachmentLocation的关联是指未映射的类:System.Guid]
>
中的NHibernate.Cfg.Configuration.LogAndThrow(异常异常)> d:\ CSharp\NH\NH\\\
hibernate\src\NHibernate\Cfg\Configuration.cs:342
> NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(表格,
> ISet完成)在
> d:\ CSharp \NH \ NHH \ nhibernate \\ \\ src\NHibernate\Cfg\Configuration.cs:1169
>
中的NHibernate.Cfg.Configuration.SecondPassCompile()> d:\ CSharp\NH\NH\\\
hibernate\src\NHibernate\Cfg\Configuration.cs:1120
>
>中的NHibernate.Cfg.Configuration.BuildSessionFactory(); d:\ CSharp\NH\NH\\\
hibernate\src\NHibernate\Cfg\Configuration.cs:1249
>
>中的FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory(); d:\Builds \FluentNH-v1.x-nh3 \src \FluentNHibernate\Cfg \FluentConfiguration.cs:227
>
> [FluentConfigurationException:无效或不完整的配置
>在创建SessionFactory时使用。检查PotentialReasons
>集合和InnerException以获取更多详细信息。
>
> *数据库未通过数据库方法配置。 ]
>
>中的FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory(); d:\Builds\FluentNH-v1.x-nh3 \src \FluentNHibernate\Cfg \FluentConfiguration.cs:232
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateHelper.OpenSession()
>在C:\ Users \ elad \Documents\Visual Studio
> 2010 \Projects\SVN\UGI\Ugi\Intructrastructure \Dal \Adapters \NHibernateAdapter \NHibernateHelper.cs:21
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateHelper.GetSession()
>在C:\ Users \ elad \Documents\Visual Studio
> 2010 \Projects\SVN\UGI\Ugi\Intructrastructure \Dal \Adapters \NHibernateAdapter \NHibernateHelper.cs:36
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateDal`1..ctor()
>在C:\ Users \ elad \Documents\Visual Studio
> 2010 \Projects\SVN\UGI\Ugi\Intructrastructure \Dal \Adapters \NHibernateAdapter \NHibernateDal.cs:16
> Ugi.Infrastructure.Dal.Adapters.NHibernateAdapter.NHibernateDalFactory.GetDal()
>在C:\ Users \ elad \Documents\Visual Studio
> 2010 \Projects\SVN\UGI\Ugi\Intructrastructure \Dal \Adapters \NHibernateAdapter \NHibernateDalFactory.cs:17
>
中的Ugi.Server.Sources.Logic.SourcesService..ctor()> 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) c:\ EntLib \ UnityTemp \ Compile \Unity \Unity \Src \ ObjectBuilder \Strategies\BuildPlan \DynamicMethod \ DynamicMethodBuildPlan.cs:37
>
>中的Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
> context) c:\ EntLib \ UnityTemp \ Compile \Unity \Unity \Src \ ObjectBuilder \Strategies\BuildPlan \BuildPlanStrategy.cs:43
>
>中的Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
> context) c:\ EntLib \ UnityTemp \ Compile \Unity \Unity \Src \ ObjectBuilder \Strategies \StrategyChain.cs:110
>
>中的Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型t,对象
>现有,字符串名称,IEnumerable`1 resolverOverrides) c:\ EntLib \ UnityTemp \ Compile \Unity\Unity\Src\UnityContainer.cs:512
>
> [ResolutionFailedException:依赖项的解析失败,键入
> =Ugi.Common.Model.Sources.ISourcesService,name =(none)。在以下情况下发生异常:调用构造函数
> Ugi.Server.Sources.Logic.SourcesService()。例外情况是:
> FluentConfigurationException - 无效或不完整的配置
>在创建SessionFactory时使用。检查PotentialReasons
>集合和InnerException以获取更多详细信息。
>
> *数据库未通过数据库方法配置。
< / attachmentlocaionmap>





如何解决这个问题?



TIA

解决方案

我也有类似的问题,我对这个hibernate&流利的休眠。



我的表架构如下所示

  CREATE   TABLE  [dbo]。[MyChildImmunisations](
[Child_id] [ int ] NOT NULL
[Schedule_id] [ int ] NOT NULL
[状态] [ int ] NOT NULL
CONSTRAINT [PK_MyChildImmunisations] PRIMARY KEY CLUSTERED

[Child_id] ASC
[Schedule_id] ASC
))





我的映射类代码li ke下面。



  protected  MyChildImmunisationMap( string  tableName)
{
Table(tableName);

CompositeId()
.KeyReference(ci = > ci.Child.Id, Child_id
.KeyReference(ci = > ci .Schedule.Id, Schedule_Id);

地图(ci = > ci.Status).CustomType< childimmunisationstatus>();
} < / childimmunisationstatus > < /跨度>


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

解决方案

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>


这篇关于表X中的关联引用了未映射的类:System.Guid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆