views:

225

answers:

2

Using SubSonic 2.2, I have this query:

string q = @"SELECT Media.Id, Media.Title FROM Media WHERE Media.UserId = 7"
DAL.MediumCollection matches = new InlineQuery().ExecuteAsCollection<DAL.MediumCollection>(q).Load();

Looping through "matches" results in every single entry in the "Media" table.

However, when I do this:

IDataReader reader = new InlineQuery().ExecuteReader(q);

It returns the correct rows. Why is ExecuteAsCollection returning something completely different from ExecuteReader? Has anyone else experience this strange behavior?

+2  A: 

I think it's because you're calling .Load(). That's overwriting your original query.

ranomore
A: 

ExecuteAsCollection() should do it.

When you call the Load() method it's just like doing new DAL.MediumCollection().Load() that returns all the data in the table.

Yitzchok