Given a class
[Table ( Name = "AllPlayerInfo" ) ]
public class AllPlayerInfo
{
[Column (IsPrimaryKey = true)]
public decimal Classes_ID { get; set; }
[Column (IsPrimaryKey = true)]
public decimal Member_ID { get; set; }
//...
}
I call
DataContext db2 = new DataContext ( sqlconnectstring );
Table<AllPlayerInfo> api = db2.GetTable<AllPlayerInfo> ();
which returns all the records from the database table.
I look at the contents of api
and confirm that the record I want is there and has Member_ID == 4617
.
So I issue following command:
AllPlayerInfo attempt1 = api.Where ( r => r.Member_ID == 4617).FirstOrDefault<AllPlayerInfo> ();
that (incorrectly) returns null
.
So then I transfer the object to a list:
List<AllPlayerInfo> listapi = api.ToList<AllPlayerInfo> ();
and then use the Exists
method and it does find the record I wanted:
bool recordexists = listapi.Exists ( r => r.Member_ID == 4617 );
recordexists
is true
!
So the question is: Why does the Where
method not find the record when it is clearly there? I did try the Where
method with other fields and values and they worked. Just not this particular field. I tested other decimal fields such as the class_id
and it worked.