简体   繁体   中英

C# Nhibernate how to join queryover one to many

I am new NHibernate query. I have oracle table with one to many relationship as i have mentioned below. I have done the fluent nhibernate mapping and trying to run the below query but i keep getting error saying ChInfo_Id not valid. Can anyone help me what am i doing wrong here.

    var query = Session.QueryOver(() => logAlias)
                    .Inner.JoinQueryOver(()=>logAlias.ChInfo, ()=>chInfoAlias)
                    .Where(()=>logAlias.RegDate.IsBetween(fromDate).And(toDate))
                    .Future<Log>();

    return query.ToList();

Tables:

Ch_Info

Ch_no
Name

Log

portid
regdate
ch_no

Class and FluentNHibernate maps:

public class Log
{
    public virtual int PortId { get; set; }
    public virtual DateTime Regdate { get; set; }
    public virtual ChInfo ChInfo { get; set; }
}

public class ChInfo
{
    public ChInfo()
    {
        Logs = new List<Log>();
    }

    public virtual string Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Log> Logs { get; set; }        
}

public class LogMap : ClassMap<Log>
{
    public LogMap()
    {
        Table("LOG");

        CompositeId()
            .KeyProperty(x => x.PortId,"portid")
            .KeyProperty(x => x.Regdate, "regdate");

        References(x => x.ChInfo);
    }
}   
public class ChInfoMap : ClassMap<ChInfo>
{
    public ChInfoMap()
    {
        Table("Ch_Info");

        Id(x => x.Id).GeneratedBy.Assigned().Column("Ch_no");
        Map(x => x.Name).Column("Name");
        HasMany(x => x.Logs)
            .Inverse()
            .Cascade.All();
    }
}

I solved it by specifying the column name in the references in the LogMap.

public class LogMap : ClassMap<Log>
{
    public LogMap()
    {
        Table("LOG");

        CompositeId()
            .KeyProperty(x => x.PortId,"portid")
            .KeyProperty(x => x.Regdate, "regdate");

        References(x => x.ChInfo).Columne("Ch_no");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM