Mapping interface on multiple hierarchies with NHibernate -


given 2 classes not related, 1 of member of inheritance hierarchy, how can map interface on both of classes can query against interface , have appropriate concrete type returned? e.g.

public abstract class survey  {      public guid id { get; private set; }  }   public class inviteonlysurvey : survey  {      public icollection<invite> invites { get; private set; }  }   public class invite : isurveygateway  {      public guid id { get; private set; }      public inviteonlysurvey survey { get; private set; }  }   public class sharedsurvey : survey, isurveygateway { ... }   public interface isurveygateway  {      guid id { get; }  }  

currently have mapped survey, inviteonlylivesurvey , sharedlivesurvey using table per class hierarchy , trying figure out how map isurveygateway can query against , have nhibernate find matching entity ( invite or sharedlivesurvey ) seamlessly. isurveygateway instances readonly remaining persistence concerns managed through mappings sharedsurvey , invite.

if remove isurveygateway interface either sharedsurvey or invite, can query , retrieve isurveygateway instances via nhibernate, apply interface 2 different hierarchies exception message "ambiguous persister isurveygateway implemented more 1 hierarchy" (which expected - don't know how make work).

the answer queryover , futurevalue works, here simpler solution:

public isurveygateway findsurveygatewaybyid( guid id ) {   var surveygateway = session      .queryover<isurveygateway>      .where( s => s.id == id )      .singleordefault<isurveygateway>();   return surveygateway; } 

but should careful, id should guid. if it's not case may multiple responses...


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -