Does Linq to NHibernate return different results than HQL?

I have this basic entity:

public class Instrument
{
    public virtual int Id { get; set; }
    public virtual Guid? InstrumentGuid { get; set; }
    public virtual string FIPSCode { get; set; }
    public virtual IList Names {get; set;}
}

public class Name
{
    public virtual int Id {get; set;}
    public virtual string Name {get; set;}
    public virtual Instrument Instrument {get; set;}
}

Mapping:

public class InstrumentMap: ClassMap<Instrument>
{
    public InstrumentMap()
    {
        Id(x => x.Id);
        Map(x => x.InstrumentGuid).Not.Nullable();
        Map(x => x.FIPSCode).Not.Nullable();
        HasMany(x => x.Names).Casecade.All;
    }
}

public class NameMap : ClassMap<Name>
{
    public NameMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        References(x => x.Instrument);
    }
}

So why, when I do these two queries, get different results?

var namelist = from name in Session.Linq()
    where name.Instrument.Id == 1
    select name;

I get 3 results, 2 where Instrument.Id = 1 and 1, where Instrument.Id = 4 vs:

var querystr = "select name From Name as name where name.Instrument.Id = 1";
var hqlresult = Session.CreateQuery(querystr).List();

This gets only 2 results, where Instrument.Id = 1.

Can someone explain where Id = 4 comes from a Linq query, or is NHibernate.Linq not quite stable? Thank!

+3
source share
2 answers

Well, I turned on ShowSql from the Sqllite provider (which I use for testing) and found that it was creating compatible code for each choice.

- Linq ( 2.0 3.0 , SQL-. SQL sqlite3.exe, . , Id. (guid) where = Linq HQL!

, , , . - , , - .

0

linq. linq, , NHibernate.Contrib. api. api sql, hql. sql, ?

NHibernate trunk - linq hql. linq sql, hql. , . , , , .

0

Source: https://habr.com/ru/post/1735337/


All Articles