Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Why does this happen IEnumerable versus List -


i have following bl method

public static void somemethod (list<someclass> group) {     ienumerable<someclass> groupwithfalse =(from someclass gr in group                                             gr.someprop== false                                             select gr);     foreach (someclass grfalse in groupwithfalse)     {       grfalse.save();     }      if (groupwithfalse.any())     {       // stuff     } } 

the mock implementation dl saving (which cannot changed used in lot of unit tests) is:

public void save() {    group.someprop = true; } 

if try unit test last statement of flow e.g if (groupwithfalse.any()) statement fails, apparently there no more elements property set false. if change code in business logic :

public static void somemethod (list<someclass> group) {     list<someclass> groupwithfalse = new list<someclass>();     foreach (var g in group)     {       if (g.someprop == false)           groupwithfalse.add(g);     }      foreach (someclass grfalse in groupwithfalse)     {       grfalse.save();     }      if (groupwithfalse.any())     {       // stuff     } } 

the conditional statement if (groupwithfalse.any()) not fail in unit tests. why happen? thanks

running linq query not store results.
instead, re-execute query each time enumerate it.

after calling save(), query empty, since none of items meet where clause.

change

var unsaved = group.where(g => !g.someprop).tolist(); 

calling tolist() store results in list<t>; avoids re-executing query.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -