FilterCondition returns no results with SqlCE DB

Apr 14, 2014 at 9:52 AM
Edited Apr 14, 2014 at 9:54 AM
I'm trying to make a custom select statement using filter conditions. I have a table defined as follows:
    [Entity(KeyScheme = KeyScheme.Identity)]
    public class Table1
    {
        [Field(IsPrimaryKey = true)]
        public int ID { get; set; }

        [Field(AllowsNulls = false)]
        public int DisplayPosition { get; set; }

        [Field]
        public string SerialNo { get; set; }
    }
And a filter condition defined as:
SqlFilterCondition filter = new SqlFilterCondition();
filter.FieldName = "SerialNo";
filter.Value = "1234567";
filter.Operator = FilterCondition.FilterOperator.Equals;
I use this in a select statement as:
store.Select<Table1>(filter);
but this yields no results. I know the table has data in it as I can view it using CompactView. I'm trying to make the database engine perform the select rather than filtering in code using LINQ. What am I doing wrong? Thanks.
Apr 15, 2014 at 10:59 AM
Ok, I figured out the Select method uses a "yield return" result so only populates the results when ToList() is called. So this works:
var results = store.Select<Table1>(filter).ToList();
I have noticed that if I create a FilterCondition on the primary key, an "equal to" operator is always used, so something like this doesn't return the correct result set. Instead, the result with ID equal to 3 is returned (not greater than):
var filterCondition = new FilterCondition("ID", 3, FilterCondition.FilterOperator.GreaterThan);
var results = store.Select<Table1>(filterCondition).ToList();
Coordinator
Apr 16, 2014 at 2:53 PM
Yes, all of the methods in the ORM that return data return IEnumerables that are lazy loaded using yield return. The variable won't actually be populated until it is consumed. For testing, doing a ToList(), ToArray() or even a Count() will populate them, though don't make a habit of that in production, as it tends to kill any of the benefits of the yield return.

I'll take a look at the filter condition and see what's happening.