I am querying the database using Linq to Sql. Here is my data :
Name LastName Age
------------------------------
1 Abc Def 15
2 Abc Def 17
3 xyz wss 17
My Linq to Sql Code is :
Context _context = new Context("Conn_String");
var table = _context.GetTable<Person>();
List<Person> persons = table.Where<Person>(p => p.Name == "Abc" && p.LastName == "Def").ToList<Person>();
According to my understanding, This query should return 2 records. i.e. Record 1 and Record 2. But it is returning Record 1 twice. Can you enlighten me if it is a bug in Linq to Sql or something I am doing wrong?
EDIT:
This is my DAL Code:
public List<T> GetList<T>(Expression<Func<T, bool>> predicate) where T : class
{
try
{
Context _context = new Context("Conn_String");
var table = _context.GetTable<T>();
return table.Where<T>(predicate).ToList<T>();
}
catch (Exception ex)
{
throw ex;
}
}
I am calling this method as :
List<Person> person = DAL.GetList<Person>(p => p.Name == "Abc" && p.LastName == "Def");
foreach(var Person in persons )
{
// Print(person.Age);
}
