Hangi türde sorgu yapmak istiyorsunuz ? Sql, Entity Framework, Linq..
Örnek bir metod yazalım, parametre olarak kullanıcı adını alsın ve geriye Person tipinde kullanıcımızı döndürsün
EF kullanarak;
public Person GetParentCustomerNo(string userName)
{
using (MyDataEntities context = new MyDataEntities())
{
var person = context.Person.Where(t => t.UserName == userName);
if (person != null)
return person;
else
return null;
}
}
Linq kullanarak;
public Person GetParentCustomerNo(string userName)
{
using (MyDataEntities context = new MyDataEntities())
{
var user = (from p in context.Person
where p.UserName == username
select p).FirstOrDefault();
if (user != null)
return user;
else
return null
}
}