c# - Display value from other table -
i have database 2 tables. first table contains foreign key second table. in mvc-project, display value (stored in second table) instead of id first table..
in ssms join. how do in c#?
rec.title = item.title + " - " + item.appointmentlength.tostring() + " mins" + " behandlingsid " + ***item.behandlingarid***;
//
item.behandlingarid contains id change corresponding value.
these 2 tabeles:
public class appointmentdiary { public int id { get; set; } public datetime datetimescheduled { get; set; } public behandlingar behandling { get; set; } public int? behandlingarid { get; set; } } public class behandlingar { public int behandlingarid { get; set; } public string namn { get; set; } public int pris { get; set; } public int tid { get; set; } } list<diaryevent> result = new list<diaryevent>(); foreach (var item in rslt) { diaryevent rec = new diaryevent(); rec.enddatestring = item.datetimescheduled.addminutes(item.appointmentlength).tostring("s"); rec.title = item.title + " - " + item.appointmentlength.tostring() + " mins" + " behandlingsid " + item.behandlingarid; }
are expecting this?
var result=appointmentdiary.where(i=>i.behandlingarid==behandlingarid).tolist;
this give records matches behandlingarid
in appointmentdiary
table
edit :
if want other way around.
if db datacontext
var result=db.behandlingar.where(i=>i.behandlingarid == behandlingarid).firstordefault().nam;
note: behandlingarid here foreign key appointmentdiary.
say want access nam
behandlingarid=1 then
var result=db.behandlingar.where(i=>i.behandlingarid == 1).firstordefault().nam;
will give first record matches behandlingarid==1
in behandlingar
table
you can put snippet want access nam
hope helps.
Comments
Post a Comment