c# - Map navigation properties in Dapper.Net using stored procedure -


i using dapper.net data sql server database.

here poco classes

public partial class production {     public system.guid productionid { get; set; }     public system.guid surveyid { get; set; }     public nullable<int> percentcomplete { get; set; }     public string completedby { get; set; }     public string deliverto { get; set; }      public virtual surveyjob surveyjob { get; set; } }   public partial class surveyjob  {         public surveyjob()         {             this.productions = new hashset<production>();         }          public system.guid surveyid { get; set; }         public string jobtitle { get; set; }         public nullable<int> status { get; set; }         public nullable<int> jobnumber { get; set; }         public nullable<system.datetime> surveydate { get; set; }         public nullable<system.datetime> requiredby { get; set; }         public virtual icollection<production> productions { get; set; } } 

i want productions along surveyjob information. here sql query in stored procedure returns these columns

select      p.productionid, s.surveyid,      p.percentcomplete, p.completedby, p.deliverto,      s.jobtitle, s.jobnumber, s.requiredby, s.status, s.surveydate      dbo.production p with(nolock) inner join      dbo.surveyjob s with(nolock) on s.surveyid = p.surveyid  

problem getting production data surveyjob object null.

here c# code

var result = await connection.queryasync<production>("[dbo].[getallproductions]", p, commandtype: commandtype.storedprocedure); 

i getting surveyjob object null shown in image.

need help. doing wrong?

enter image description here

your model malformed query executed, query return plain object (dapper return plain objects), need class properties you're selecting.

change model this:

public partial class productionsurvey {     public system.guid productionid { get; set; }     public system.guid surveyid { get; set; }     public nullable<int> percentcomplete { get; set; }     public string completedby { get; set; }     public string deliverto { get; set; }     public system.guid surveyid { get; set; }     public string jobtitle { get; set; }     public nullable<int> status { get; set; }     public nullable<int> jobnumber { get; set; }     public nullable<system.datetime> surveydate { get; set; }     public nullable<system.datetime> requiredby { get; set; } } 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -