Samio

Samio

  • NA
  • 201
  • 176.4k

LINQ to Entities Small code to test data retrieval C# WinForms

Mar 19 2012 6:37 PM
Hi

Could not get this to work, When I Run project no console is displayed

also as I am new to Entity Framework with C# winforms, I would like to ask how to fill a TextBox with a context item.

I am using Visual studio 2010 version and MS SQL 2008 Express.

Thank you

Code:

using System;
using System.Data.Objects;
using System.Linq;
using System.Windows.Forms;


namespace MyNameSpace
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  private void BtnOk_Click(object sender, EventArgs e)
  {

  using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
  {
  ObjectQuery<Employee> Employee = MyEntities.Employee;
  var query = from p in Employee
  where p.FirstName == "Jane"
  select new { p.ID, p.LastName, p.FirstName, p.Birth };
  foreach (var ligne in query)
  Console.WriteLine(ligne.ID + " " + ligne.LastName + " " + ligne.FirstName);
  }
  Console.Read();
  }
  }
}

Answers (13)