c# - Populating List with related information -


i have list view populated using controller:

        public actionresult listclubmembershiptype(int clubid)     {         //populate list         var types = s in db.membershiptypes                     (s.clubid == clubid)                     orderby s.type                     select s;         viewbag.typescount = types.count();         var model = types.select(t => new listmembershiptypeviewmodel                 {         type = t.type,         clubid = clubid,         cost = t.cost,         reducedcost = t.reducedcost,         minage = t.minage,         maxage = t.maxage,     });          return partialview("_listclubmembershiptype", model);     } 

i populate variable in view model called reduceddate data pulled 2 other tables, day & month.

ive tried following line:

            reduceddate = db.days.find(t.dayid).daynum + "/" + db.months.find(t.monthid).monthname, 

but gives following error:

additional information: method 'grcwebapp.models.day find(system.object[])' declared on type 'system.data.entity.dbset1[grcwebapp.models.day]' cannot called instance of type 'system.data.entity.core.objects.objectquery1[grcwebapp.models.day]'

what correct way reference data?

the models are:

membershiptype

public int membershiptypeid { get; set; }  [stringlength(150)] [column(typename = "nvarchar")] public string type { get; set; }  [stringlength(350)] [column(typename = "nvarchar")] public string description { get; set; }  [column(typename = "int")] public int clubid { get; set; }  [column(typename = "decimal")] public decimal cost { get; set; }  [column(typename = "decimal")] public decimal reducedcost { get; set; }  [column(typename = "int")] public int? dayid { get; set; }  [column(typename = "int")] public int? monthid { get; set; }  [column(typename = "int")] public int minage { get; set; }  [column(typename = "int")] public int maxage { get; set; }  [column(typename = "bit")] public bool? dormant { get; set; } } 

the day model:

public class day { public int dayid { get; set; }  [column(typename = "int")] public int daynum { get; set; }  public virtual icollection<membershiptype> membershiptypes { get; set; } } 

the month model:

    public class month { public int monthid { get; set; }  [column(typename = "nvarchar")] public string monthname { get; set; }  public virtual icollection<membershiptype> membershiptypes { get; set; } } 

and viewmodel is:

    public class listmembershiptypeviewmodel { [display(name = "type")] public string type { get; set; }  public int clubid { get; set; }  [display(name = "full cost")] public decimal cost { get; set; }  [display(name = "reduced cost")] public decimal reducedcost { get; set; }  [display(name = "reduced from")] public string reduceddate { get; set; }  [display(name = "min age")] public int minage { get; set; }  [display(name = "max age")] public int maxage { get; set; } } 

you have dayid , monthid on membershiptype don't have properties of public day day {get;set;} , public month month {get;set;}

if had properties use reduceddate = t.day.daynum + "/" + t.month.monthname

this might give error since daynum int you'll need convert daynum string. can use sqlfunctions.stringconvert((double)t.day.daynum) this.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -