1

我尝试使用 NHibernate 进行休闲:

this.Session.CreateQuery(@"insert into ContactGroupContact (Id, MailAddress, Company, Person, Branch, ContactGroup, User, FaxNumber)
                             select newid(), MailAddress, Company, Person, Branch, 
                                    :destContactGroupId, User, FaxNumber
                             from ContactGroupContact cgc
                             where cgc.ContactGroup.Id = :contactGroupId")
        .SetEntity("destContactGroupId", tempContactGroup)
        .SetGuid("contactGroupId", contactGroupId)
        .ExecuteUpdate();

的列IdContactGroupContact类型GUID

当我执行此操作时,我收到NHibernate.QueryException以下消息:

节点没有数据类型: MethodNode ( ( newid exprList ) [插入 ContactGroupContact (Id, MailAddress, Company, Person, Branch, ContactGroup, User, FaxNumber) select newid(), MailAddress, Company, Person, Branch, :destContactGroupId, User , 来自 ContactGroupContact cgc 的传真号码,其中 cgc.ContactGroup.Id = :contactGroupId]

有人可以帮我吗,出了什么问题?- 谢谢。

4

2 回答 2

1

这是 Diego 建议的一个例子。我承认我对此并不陌生,但假设这是处理它的适当方法(它有效)

public class DerivedDialectWithNewId : MsSql2005Dialect
{
    public DerivedDialectWithNewId()
    {
        RegisterFunction("newid", new NoArgSQLFunction("newid", NHibernateUtil.Guid, true));        
    }
}

这里是如何将它与 Fluent NHibernate 一起使用

private static FluentConfiguration GetConfiguration()
    {
        return Fluently.Configure()
            .Database(
                MsSqlConfiguration.MsSql2005.ConnectionString(
                    c => c.FromConnectionStringWithKey("CustomConnectionString"))
                    .Dialect<DerivedDialectWithNewId>()));
    }
于 2012-11-19T23:40:52.253 回答
1

尝试创建派生Dialect并注册newid为函数。

于 2012-07-17T20:01:48.313 回答