![](/img/trans.png)
[英]How to configure Fluent NHibernate to output queries to Trace or Debug instead of Console?
[英]NHibernate Fluent and named Queries
我有以下名為Queryé的查詢,我希望將其結果映射到一個類上。
<sql-query name="GetIndustryCodes">
<return class="IndustryCode">
<return-property name="Sector_kategorie" column="Sector_kategorie"/>
<return-property name="Sector_scheme_reference" column="Sector_scheme_reference"/>
<return-property name="Group_Beschreibung" column="Group_Beschreibung"/>
</return>
<![CDATA[
select * from
(
select
lvl1.sprach_iso_cd,
lvl1.kategorie Sector_kategorie,
lvl1.scheme_reference Sector_scheme_reference,
lvl1.Beschreibung Sector_Beschreibung,
lvl2.kategorie Group_kategorie,
lvl2.scheme_reference Group_scheme_reference,
lvl2.Beschreibung Group_Beschreibung,
lvl3.kategorie Industry_kategorie,
lvl3.scheme_reference Industry_scheme_reference,
lvl3.Beschreibung Industry_Beschreibung,
lvl4.kategorie Subindustry_kategorie ,
lvl4.scheme_reference Subindustry_scheme_reference,
lvl4.Beschreibung Subindustry_Beschreibung
from StagingDb.Rds.GR3_S_R10916_TX lvl1
left join StagingDb.Rds.GR3_S_R10916_TX lvl2
on lvl2.sprach_iso_cd = lvl1.sprach_iso_cd
and lvl2.kategorie = 'MSCIS&PGroup'
and lvl1.scheme_reference = substring(lvl2.scheme_reference,1,2)
left join StagingDb.Rds.GR3_S_R10916_TX lvl3
on lvl3.sprach_iso_cd = lvl1.sprach_iso_cd
and lvl3.kategorie = 'MSCIS&PIndustry'
and lvl2.scheme_reference = substring(lvl3.scheme_reference,1,4)
left join StagingDb.Rds.GR3_S_R10916_TX lvl4
on lvl4.sprach_iso_cd = lvl1.sprach_iso_cd
and lvl4.kategorie = 'MSCIS&P'
and lvl3.scheme_reference = substring(lvl4.scheme_reference,1,6)
where lvl1.kategorie = 'MSCIS&PSector'
) t
where t.sprach_iso_cd ='en'
]]>
</sql-query>
我也有一個C#課
public class IndustryCode
{
public virtual string Sector_kategorie { get; set; }
public virtual string Sector_scheme_reference { get; set; }
public virtual string Sector_Beschreibung { get; set; }
public virtual string Group_kategorie { get; set; }
public virtual string Group_scheme_reference { get; set; }
public virtual string Group_Beschreibung { get; set; }
public virtual string Industry_kategorie { get; set; }
public virtual string Industry_scheme_reference { get; set; }
public virtual string Industry_Beschreibung { get; set; }
public virtual string Subindustry_kategorie { get; set; }
public virtual string Subindustry_scheme_reference { get; set; }
public virtual string Subindustry_Beschreibung { get; set; }
}
現在,在啟動程序時,我得到了異常é創建SessionFactory時使用了無效或不完整的配置。 檢查PotentialReasons集合和InnerException以獲取更多詳細信息。
InnerExceptioné“詞典中不存在給定的鍵。”
如果我在不使用返回類的情況下使用查詢,那么它工作得很好,除了獲得未映射到類中的返回值。 但是該類肯定在組裝中。 如何將查詢映射到類中?
非常感謝你
我沒有任何類映射到數據庫。 下面的代碼為我工作。 Desk在Desk.hbm.xml文件中定義的位置。
public class NHibernateHelper
{
private readonly string _connectionString;
private ISessionFactory _sessionFactory;
public NHibernateHelper(string connectionString)
{
_connectionString = connectionString;
}
public ISessionFactory SessionFactory
{
get { return _sessionFactory ?? (_sessionFactory = CreateSessionFactory()); }
}
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(_connectionString))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
.Mappings(m => m.HbmMappings.AddClasses(typeof(Desk)))
.BuildSessionFactory();
}
}
經過一番黑客攻擊后,我確信只能將某些SP的輸出映射到具有映射到DB的Class。
因此,僅具有sp並將其映射到某個類將不起作用。 該類必須具有映射,因此該類必須是域模型的類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.