Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>given these requirements there would be no difference, the generated SQL is the same: for mappings:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="Project" table="Project"&gt; &lt;id name="Id" type="Int32" unsaved-value="0"&gt; &lt;column name="Id" sql-type="int" not-null="true" unique="true"/&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="Job" column="FK_JobId" cascade="save-update" not-null="true" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="Job" table="Job"&gt; &lt;id name="Id" type="Int32" unsaved-value="0"&gt; &lt;column name="Id" sql-type="int" not-null="true" unique="true"/&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="Name" type="String"&gt; &lt;column name="Name" sql-type="nvarchar" length="50" not-null="true"/&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>and classes </p> <pre><code>public class Project { public Project() { } public virtual int Id { get; set; } public virtual Job Job { get; set; } } public class Job { public Job() { } public virtual int Id { get; set; } public virtual String Name { get; set; } } </code></pre> <p>these criteria definitions </p> <pre><code>ICriteria criteriacrit = session .CreateCriteria(typeof (Project)) .CreateCriteria("Job", "job") .Add(Restrictions.Eq("job.Name", "sometextA")); ICriteria aliascrit = session .CreateCriteria(typeof (Project)) .CreateAlias("Job", "job") .Add(Restrictions.Eq("job.Name", "sometextB")); </code></pre> <p>generate the same SQL</p> <pre><code>SELECT this_.Id as Id2_1_, this_.FK_JobId as FK2_2_1_, job1_.Id as Id1_0_, job1_.Name as Name1_0_ FROM Project this_ inner join Job job1_ on this_.FK_JobId=job1_.Id WHERE job1_.Name = @p0; @p0 = 'sometextA' SELECT this_.Id as Id2_1_, this_.FK_JobId as FK2_2_1_, job1_.Id as Id1_0_, job1_.Name as Name1_0_ FROM Project this_ inner join Job job1_ on this_.FK_JobId=job1_.Id WHERE job1_.Name = @p0; @p0 = 'sometextB' </code></pre> <p>note however that the <code>CreateAlias</code> relies on the mappings to generate associations whereas the <code>CreateCriteria</code> call allows to specify <code>JoinType</code>. </p> <p>so, these calls</p> <pre><code>ICriteria criteriacrit = session .CreateCriteria(typeof(Project)) .CreateCriteria("Job",JoinType.LeftOuterJoin) .Add(Restrictions.Eq("Name", "sometextA")); ICriteria aliascrit = session .CreateCriteria(typeof (Project)) .CreateAlias("Job", "job") .Add(Restrictions.Eq("job.Name", "sometextB")); </code></pre> <p>generate these SQL statements</p> <pre><code>SELECT this_.Id as Id2_1_, this_.FK_JobId as FK2_2_1_, job1_.Id as Id1_0_, job1_.Name as Name1_0_ FROM Project this_ **left outer** join Job job1_ on this_.FK_JobId=job1_.Id WHERE job1_.Name = @p0; @p0 = 'sometextA' SELECT this_.Id as Id2_1_, this_.FK_JobId as FK2_2_1_, job1_.Id as Id1_0_, job1_.Name as Name1_0_ FROM Project this_ **inner join** Job job1_ on this_.FK_JobId=job1_.Id WHERE job1_.Name = @p0; @p0 = 'sometextB' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload