Reputation: 15399
I'm running a C# project compiled against .NET 3.5 in VS 2010 SP 1 on a Windows 8 machine with .NET 4.5 installed, if that matters.
I have a method that looks like the following:
private IEnumerable<TModel> ExecuteAndGet<TModel>(string name, IEnumerable<SqlParameter> parameters)
where TModel : new()
{ // <-- Breakpoint 1
// Non-trivial code so I doubt the method call is being optimized away
// Or something if that's even possible.
}
In the same class in a different method I call ExecuteAndGet
like so:
this.ExecuteAndGet<object>("[dbo].[SomeStoredProcedure]", parameters); // <-- Breakpoint 2
That's definitely the only overload of that method. While running the program in debug mode I hit breakpoint 2. I've tried just regular "F5" and "Step INTO" but it completely skips going inside the method altogether and it skips breakpoint 1. I have no idea why this is happening. Other calls to ExecuteAndGet
are working and I don't see why this is any different. Help, please?
Thanks.
Upvotes: 0
Views: 121
Reputation: 1217
The enumerable returned is implemented as an iterator block. Code inside iterator blocks does not actually execute until they are enumerated for the first time, e.g. add call .ToArray()
or .ToList()
Upvotes: 1
Reputation: 23324
You're not actually enumerating. Try:
this.ExecuteAndGet<object>("[dbo].[SomeStoredProcedure]", parameters).ToList();
Upvotes: 3