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.

.net - EF CodeFirst CTP5 with Repository and UnitOfWork: System.InvalidOperationException (...not part of... ...current context...) -


i'm testing ef codefirst ctp5 , trying implement unit of work , repository patterns. when run simple test get:

system.invalidoperationexception : entity type log not part of model current context.

the database get's created ef , fails when call .add() seems same context not being used can't figure out why?

hoping smart human coming rescue me!
in advance taking time.

here code:

logcabincontext

public class logcabincontext : dbcontext, iunitofwork {     public logcabincontext() { }      public logcabincontext(string nameorconnectionstring)         : base(nameorconnectionstring)     {      }      #region iunitofwork members      public void save()     {         base.savechanges();     }      #endregion } 

baserepository

public class baserepository<t> : ibaserepository<t> t : entitybase {     public logcabincontext _unitofwork;     private dbset<t> _dbset;      public baserepository(iunitofwork unitofwork)     {         if (unitofwork == null)             throw new nullreferenceexception("unitofwork must not null");          _unitofwork = unitofwork logcabincontext;         _dbset = _unitofwork.set<t>();     }      #region ibaserepository members      public t getbyid(int id)     {         return _dbset.singleordefault(x => x.id == id);     }      public void add(t entity)     {         _dbset.add(entity);     }      public void delete(t entity)     {         _dbset.remove(entity);     }      public ienumerable<t> list()     {         return _dbset.orderby(x => x.id).asenumerable();     }      public iunitofwork currentunitofwork     {         { return _unitofwork; }     }     #endregion      #region idisposable members      public void dispose()     {         _unitofwork.dispose();     }      #endregion } 

simpletest, using ninject build context, works since creates db

[testfixture] public class logrepositorytests {     ikernel _kernel;      [setup]     public void setup()     {         _kernel = new standardkernel(new databasemodule());     }      [teardown]     public void teardown()     {         _kernel.dispose();     }     public ilogrepository getlogrepository()    {         ilogrepository logrepo = _kernel.get<ilogrepository>();          return logrepo;    }     [test]    public void test()    {         using (ilogrepository repo = this.getlogrepository())         {            log mylog = new log();            mylog.application = "test";            mylog.date = datetime.now;            mylog.exception = "exception message";            mylog.machinename = "local";            mylog.message = "testing";            mylog.stacktrace = "stacktrace";             repo.add(mylog);         }    } } 

ilogrepository, derives base now

public interface ilogrepository : ibaserepository<log> { } 

answered here: entity framework 4 ctp 4 / ctp 5 generic repository pattern , unit testable


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 -