Posts

Showing posts with the label Castle Windsor

Donate

An object with the same key already exists in the ObjectStateManager. (Entity Framework 6.0)

The code below for updating of objects worked with Entity Framework 5 and below. But using this with Entity Framework 6.0 and Castle Windsor as IOC Container, I get an error message with is the title of this post. 1 2 3 4 5 6 7 8 public void Update(BookDetail item) { if (item!= null ) { _context.Entry(item).State = System.Data.Entity.Entitystate.Modified; _context.SaveChanges(); } } So to fix this, replace the code above with DBContext.Entry(T Entity).CurrentValues.SetValues(T Entity). 1 2 3 4 5 6 7 8 9 10 11 12 public void Update(BookDetail item) { if (item != null ) { var result = _context.BookDetails.Find(item.BookSerialNo); if (result != null ) { _context.Entry(result).CurrentValues.SetValues(item); _context.SaveChanges(); } } }

Castle.MicroKernel.Registration.AllTypes' is obsolete in ASP.NET MVC 5

In the event that you'll be referencing Castle Windsor 3.3.0 and incorporate the IOC container in your project, you will encounter the error stated by the title of this post. This happens when you use register the controllers to the IOC container using AllTypes class. 1 2 3 4 container.Register(AllTypes.FromThisAssembly() .Pick().If(t => t.Name.EndsWith( "Controller" )) .Configure(configurer => configurer.Named(configurer.Implementation.Name)) .LifestylePerWebRequest()); This class has been deprecated in the recent versions of Castle Windsor. The solution is to update the Register method and replace AllTypes with Castle.MicroKernel.Registration.Classes . 1 2 3 4 container.Register(Classes.FromThisAssembly() .Pick().If(t=> t.Name.EndsWith( "Controller" )) .Configure(configurer => configurer.Named(configurer.Implementation.Name)) .LifestylePerWebRequest());

Castle Windsor - Could Not Perform FindAll() For (Model) Using ActiveRecordBase in Castle.ActiveRecord ORM

When running a simple asp.net mvc project, I encountered an error which states the Model.FindAll() could not be performed. Model is a class that maps to a database table. After tracing my codes, I found out that I have mispelled the database name in my web.config as specified below: <add key= "connection.connection_string" value= "Data Source=MyComputerStation\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Blogs.mdf;Integrated Security=True;User Instance=True" /> What I did was change the database name from Blogs to Blog . That's it! :) Greg

Donate