Link the LINQ query to FastReport and get only one row of data

In the following code, when I click the button, it will show all the entries in the User table instead of giving me one that has (UserID == 17).

 ReGdbEntities re = new ReGdbEntities();
 private void buttonX1_Click(object sender, EventArgs e)
 {
     Report report = new Report();
     string fileName = Application.StartupPath + @"\Reports\Untitled.frx";
     var jfja = re.Users.Where(u => u.UserID == 17);
     report.RegisterData(jfja.ToList(), "User");
     report.GetDataSource("User").Enabled = true;
     report.Load(fileName);
     report.Prepare();
     report.Preview = this.previewControl1;
     report.Show();
 }
+4
source share
1 answer

The table must have more than one record with the same identifier 17 in your database.

If you need only the first record of the search result, you can use the FirstOrDefault method.

var jfja = re.Users.Where(u => u.UserID == 17).FirstOrDefault();
+1
source

Source: https://habr.com/ru/post/1584631/


All Articles