サンプルに3つのテーブルがあります。私は2つのテーブルに参加するつもりですが、次の問題があります:私のコード:
<?xml version="1.0"?>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=(local);database=human;Integrated Security=SSPI;</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
using System.Collections.Generic;
using System.Text;
using System;
namespace human {
public class TblStudent {
public TblStudent() { }
public virtual int ID { get; set; }
public virtual IList<TblTerm> TblTerms { get; set; }
public virtual string name { get; set; }
public virtual string lastname { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using FluentNHibernate.Mapping;
namespace human {
public class TblStudentMap : ClassMap<TblStudent> {
public TblStudentMap() {
Table("TblStudent");
LazyLoad();
Id(x => x.ID).GeneratedBy.Identity().Column("ID");
Map(x => x.name).Column("name");
Map(x => x.lastname).Column("lastname");
HasMany(x => x.TblTerms);
}
}
}
using System.Collections.Generic;
using System.Text;
using System;
namespace human {
public class TblTerm {
public TblTerm() { }
public virtual int ID { get; set; }
public virtual TblLesson TblLesson { get; set; }
public virtual TblStudent TblStudent { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using FluentNHibernate.Mapping;
namespace human {
public class TblTermMap : ClassMap<TblTerm> {
public TblTermMap() {
Table("TblTerm");
LazyLoad();
Id(x => x.ID).GeneratedBy.Identity().Column("ID");
References(x => x.TblLesson).Column("LessonID");
References(x => x.TblStudent).Column("StudentID");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using FluentNHibernate.Mapping;
namespace human {
public class TblTermMap : ClassMap<TblTerm> {
public TblTermMap() {
Table("TblTerm");
LazyLoad();
Id(x => x.ID).GeneratedBy.Identity().Column("ID");
References(x => x.TblLesson).Column("LessonID");
References(x => x.TblStudent).Column("StudentID");
}
}
}
private void button_JoinSelect_Click(object sender, EventArgs e)
{
var cfg = new Configuration();
PersistenceModel pm = new PersistenceModel();
pm.AddMappingsFromAssembly(typeof(human.TblStudent).Assembly);
pm.Configure(cfg);
ISessionFactory factory = cfg.BuildSessionFactory();
using (var session = factory.OpenSession())
{
using (var trans = session.BeginTransaction())
{
var query = session.QueryOver<TblStudent().JoinQueryOver<TblTerm>
(c=> c.TblTerms).List();
trans.Commit();
dataGridView1.DataSource = query;
}
}
}
私のエラー:
NHibernate.Exceptions.GenericADOException:クエリを実行できませんでした[SELECT this_.ID as ID1_1_、this_.name as name1_1_、this_.lastname as lastname1_1_、tblterm1_.ID as ID2_0_、tblterm1_.LessonID as LessonID2_0_、tblterm1_.StudentID as StudentID2_0_内部結合TblTermtblterm1_on this_.ID = tblterm1_.TblStudent_id] [SQL:SELECT this_.ID as ID1_1_、this_.name as name1_1_、this_.lastname as lastname1_1_、tblterm1_.ID as ID2_0_、tblterm1_.LessonID as LessonID2_0_、 as StudentID2_0_ FROM TblStudent this_ inner join TblTerm tblterm1_ on this_.ID = tblterm1_.TblStudent_id] ---> System.Data.SqlClient.SqlException:無効な列名'TblStudent_id'。System.Data.SqlClient.SqlConnection.OnError(SqlException例外、ブール値breakConnection)でSystem.Data.SqlClient.SqlInternalConnectionで。1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1595
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Criteria\CriteriaLoader.cs:line 74
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1919
at NHibernate.Impl.CriteriaImpl.List(IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 265
at NHibernate.Impl.CriteriaImpl.List[T]() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 276
at NHibernate.Impl.CriteriaImpl.Subcriteria.List[T]() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 813
at NHibernate.Criterion.QueryOver
1.List()in d:\ CSharp \ NH \ NH \ nhibernate \ src \ NHibernate \ Criterion \ QueryOver.cs:line 57 at NHibernate.Criterion.QueryOver`1.NHibernate.IQueryOver.List()in d:\ CSharp \ NH \ NH \ nhibernate \ src \ NHibernate \ Criterion \ QueryOver.cs:line 198 at human.Form1.button_JoinSelect_Click(Object sender、EventArgs e)in E:\ desktop \ Human \ human \ human \ Form1.cs:line 84
教えてください