Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate HasManyToMany only works on first load
    primarykey
    data
    text
    <p>This is a weird one for me. I have a simple domain with 2 entities Company and Carrier. They have a m:m relation via another table.</p> <p>I set up my Fluent mappings as so</p> <pre><code> public partial class Carrier { public virtual int ID { get; set; } public virtual string Name { get; set; } public virtual IList&lt;Company&gt; Companies { get; set; } } public class CarrierMap : ClassMap&lt;Carrier&gt; { public CarrierMap() { Id(x =&gt; x.ID); Map(x =&gt; x.Name); HasManyToMany(x =&gt; x.Companies) .Table("CompanyCarrier"); } } public partial class Company { public virtual int ID { get; set; } public virtual string CompanyName { get; set; } } public class CompanyMap : ClassMap&lt;Company&gt; { public CompanyMap() { Id(x =&gt; x.ID); Map(x =&gt; x.CompanyName); } } </code></pre> <p>And I have a simple linq query to get the Carriers based on company</p> <pre><code> public IQueryable&lt;Carrier&gt; GetCarriersByCompany(Company company) { return from t in _session.Linq&lt;Carrier&gt;() where t.Companies.Contains(company) select t; } </code></pre> <p>And call it all in a MVC controller Company company = _session.AuthenticatedSellerCompany; IList carriers = _carrierRepository.GetCarriersByCompany(company) .ToList();</p> <p>Here's the thing. It works <strong>perfectly</strong> the first time, and fails every time after that, until I recompile again. So I know on some level the query and mappings work!</p> <p>The error I get is :</p> <pre><code>Non-static method requires a target. </code></pre> <p>Stepping through the debugger and digging deeper I get :</p> <pre><code>PropertyAccessException Exception occurred getter of CCMvc.Core.Entities.Company.ID </code></pre> <p>Further, if I reverse the mappings, put a IList Carriers on the Company entity, and try to get a filtered list of companies by a Carrier, it works every time, but I don't know why. There is nothing special about either table or the m:m table binding them.</p> <p>Help?!</p>
    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. This table or related slice is empty.
    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