Home > Net >  O one-on-one query
O one-on-one query

Time:11-27

 
Public class Student
{
[Key]
Public int Id {get; set; }
Public string Name {get; set; }
Public StudentAddress StudentAddress {get; set; }
}

Public partial class StudentAddress
{
[Key, ForeignKey (" Student ")]
Public int Studentid {get; set; }
Public string City {get; set; }
Public string Zipcode {get; set; }
Public string Country {get; set; }
Public Student Student {get; set; }
}



Asked to query the all Student information

CodePudding user response:

Var studentinfo=(from x in student
Join in studentaddress on x.i d y equals y.s tudentid
Where x.i d==XXX). Select (z=& gt; New {student=z.x, studentaddress=z.y}). The first ()

CodePudding user response:

reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
var studentinfo=(from x in student
Join in studentaddress on x.i d y equals y.s tudentid
Where x.i d==XXX). Select (z=& gt; New {student=z.x, studentaddress=z.y}). The first ()

An error in the

CodePudding user response:

No one query,
Direct
Var stu=Student. First (x=& gt; Id==1);
If you want to use the first address address,
It is stu. Address. The First ();

CodePudding user response:

Var studentinfo=the from x in student
Join in studentaddress on x.i d y equals y.s tudentid
Select new ViewModel where x.i d==XXX (can be put in the display field you) {
. Write what you want to display inside field
};
  •  Tags:  
  • LINQ
  • Related