我正在尝试制作一个小概念验证应用,以决定我们是否可以在下一个项目中使用Linq2Hibernate。
我们使用的数据库是一个标准的informix数据库,但我不希望这会产生太大的影响......(希望如此!)
我对没有子句的单个select的代码就像一个句子,但是在添加了where子句之后我得到了参数错误:
Test method TestProject3.NHibTest.TestMethod1 threw exception:
NHibernate.Exceptions.GenericADOException: could not execute query
[ select brand0_.br_code as br1_0_, brand0_.br_name as br2_0_ from Brands brand0_ where brand0_.br_name=? ]
Name:p1 - Value:Name
[SQL: select brand0_.br_code as br1_0_, brand0_.br_name as br2_0_ from Brands brand0_ where brand0_.br_name=?] ---> System.IndexOutOfRangeException: Invalid index 0 for this IfxParameterCollection with Count=0.
此代码如下所示。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Driver;
using NHibernate.Dialect;
using NHibernate.Linq;
namespace BLL
{
public class Brand
{
public virtual int? Id { get; set; }
public virtual string Name { get; set; }
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
IfxOdbcConfiguration
.Informix1000
.ConnectionString("Server=bylgia:9525;Database=baccman_dev;UID=ewebreps;PWD=kn1ght;")
.Provider("NHibernate.Connection.DriverConnectionProvider")
.Driver<IfxDriver>()
.Dialect<InformixDialect>()
)
.Mappings(
m => m.FluentMappings.AddFromAssemblyOf<Brand>())
.BuildSessionFactory();
}
public virtual List<Brand> GetBrandsLinq()
{
var sessionFactory = CreateSessionFactory();
using (var session = sessionFactory.OpenSession())
{
return session.Query<Brand>().Where(x => x.Name == "Name").ToList();
}
}
}
public class BrandMap : ClassMap<Brand>
{
public BrandMap()
{
Table("Brands");
Id(x => x.Id, "br_code");
Map(x => x.Name, "br_name");
}
}
}
在谷歌周围进行了一次良好的搜索后,看来L2N上没有太多了!
我正在使用NuGet的NHib v3.2.0.4
由于