如何将sql函数映射为命名查询与Nhibernate';什么是语言映射?

如何将sql函数映射为命名查询与Nhibernate';什么是语言映射?,nhibernate,named-query,mapping-by-code,Nhibernate,Named Query,Mapping By Code,我已将所有NHibernate xml映射文件替换为冗长的映射(代码映射)。我唯一搞不清楚的是,是否可以使用冗长的映射定义此命名查询: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping namespace="Domain" assembly="Domain" xmlns="urn:nhibernate-mapping-2.2"> <sql-query name="MyFunction">

我已将所有NHibernate xml映射文件替换为冗长的映射(代码映射)。我唯一搞不清楚的是,是否可以使用冗长的映射定义此命名查询:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Domain" assembly="Domain" xmlns="urn:nhibernate-mapping-2.2"> 
  <sql-query name="MyFunction">
    <query-param name="Inputparam1" type="Int32"/>
    <query-param name="Inputparam2" type="Int32"/>
    <return-scalar column="ResultParam" type="Int32"/>
    <![CDATA[ select MyFunction(:Inputparam1,:Inputparam2) as ResultParam ]]>
  </sql-query>
</hibernate-mapping>

有没有人知道这是否可能,以及如何做到这一点或为我指出正确的方向

提前感谢,,
关于这一点,Ted

您仍然可以混合您的映射,即使用代码映射的所有新功能,并且仍然有一些HBM命名的映射文件

解决方案非常简单,首先需要将web.config(或外部nhibernate配置文件)定义为:-


NHibernate.dialogue.mysql5dialogue
然后相应地配置NHibernate:-

var mapper = new ModelMapper();
mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes());
//Notice the .Configure, this is the magic that allows you to
//  use the mixed mappings
var configure = new Configuration().Configure();
configure.DataBaseIntegration(x =>
{
  x.Dialect<MySQL5Dialect>();
  x.ConnectionStringName = "db";
}).CurrentSessionContext<WebSessionContext>();

configure.AddDeserializedMapping(mapping, "Domain");
SessionFactory = configure.BuildSessionFactory();
var-mapper=newmodelmapper();
AddMappings(typeof(CmsMeta.Assembly.GetTypes());
//请注意.Configure,这是允许您
//使用混合映射
var configure=新配置().configure();
configure.DataBaseIntegration(x=>
{
x、 方言();
x、 ConnectionStringName=“db”;
}).CurrentSessionContext();
configure.AddDeserializedMapping(映射,“域”);
SessionFactory=configure.BuildSessionFactory();

关于这一点,我已经写了一篇文章。

您仍然可以混合您的映射,即使用代码映射的所有新功能,并且仍然有一些名为HBM的映射文件

解决方案非常简单,首先需要将web.config(或外部nhibernate配置文件)定义为:-


NHibernate.dialogue.mysql5dialogue
然后相应地配置NHibernate:-

var mapper = new ModelMapper();
mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes());
//Notice the .Configure, this is the magic that allows you to
//  use the mixed mappings
var configure = new Configuration().Configure();
configure.DataBaseIntegration(x =>
{
  x.Dialect<MySQL5Dialect>();
  x.ConnectionStringName = "db";
}).CurrentSessionContext<WebSessionContext>();

configure.AddDeserializedMapping(mapping, "Domain");
SessionFactory = configure.BuildSessionFactory();
var-mapper=newmodelmapper();
AddMappings(typeof(CmsMeta.Assembly.GetTypes());
//请注意.Configure,这是允许您
//使用混合映射
var configure=新配置().configure();
configure.DataBaseIntegration(x=>
{
x、 方言();
x、 ConnectionStringName=“db”;
}).CurrentSessionContext();
configure.AddDeserializedMapping(映射,“域”);
SessionFactory=configure.BuildSessionFactory();

关于这一点,我已经写了一封信。

你好,里波,很抱歉我忘了提及,但这正是我现在所知道的。。我只是想知道我是否会完全丢失xml文件。顺便说一句:因为你的博客,我才得到这个!几周前已经找到了。。谢谢你的博客!如果你找到了解决方案,你会把它贴在这里吗?我自己还没解决这个问题雪人会。。在过去的一年里,我学到了很多关于NHibernate的知识。我拥有的命名查询是唯一剩下的xml格式的查询,我决定在会话中使用CreateSqlQuery执行它。它并不比使用XML更容易出错,两者都可能包含拼写错误。我用一些单元测试来覆盖它。这样我就摆脱了xml映射配置。。我只是想知道我是否会完全丢失xml文件。顺便说一句:因为你的博客,我才得到这个!几周前已经找到了。。谢谢你的博客!如果你找到了解决方案,你会把它贴在这里吗?我自己还没解决这个问题雪人会。。在过去的一年里,我学到了很多关于NHibernate的知识。我拥有的命名查询是唯一剩下的xml格式的查询,我决定在会话中使用CreateSqlQuery执行它。它并不比使用XML更容易出错,两者都可能包含拼写错误。我用一些单元测试来覆盖它。这样我就摆脱了xml映射配置。