Current filter:
                                You should refresh the page.
                                  • [DXSupport: created from the owner's comment in How to use XPO in an ASP.NET MVC application]

                                    Hello! I implemented the first solution but because I have no control over the session because every time I call XpoHelper.GetNewSession (), I create a session and then do not save a change to an object.

                                    it's my code:

                                    public ActionResult Edit(int id) { Manager manager= XpoHelper.GetNewSession().GetObjectByKey<Manager>(id); return View(manager); } [HttpPost] public ActionResult Edit([ModelBinder(typeof(Prueba002.Models.XpoModelBinder))]Mannager model) { if (model.IsChanged) { model.Save(); XpoHelper.GetNewUnitOfWork().CommitChanges(); return RedirectToAction("Index"); } return view(model); }
                                • Uriah (DevExpress Support) 11.19.2013

                                  Hello Jurgen,
                                  You do not need to obtain a new UnitOfWork instance to commit changes. The following code is sufficient:

                                  [HttpPost] public ActionResult Edit([ModelBinder(typeof(Prueba002.Models.XpoModelBinder))]Mannager model) { if (model.IsChanged) { model.Save(); return RedirectToAction("Index"); } return view(model); }

                                  If this code does not work, would you please send us the source code of your base controller and XPO model binder? We will review it and try to determine the cause of the issue.

                                • Uriah (DevExpress Support) 11.20.2013

                                  [Posted by Jurgen Ramirez]
                                  Hi! No, Is not functional, no save changes, My Code is equal a your solution

                                  public static class XpoHelper { public static Session GetNewSession() { return new Session(DataLayer); } public static UnitOfWork GetNewUnitOfWork() { return new UnitOfWork(DataLayer); } private readonly static object lockObject = new object(); static volatile IDataLayer fDataLayer; static IDataLayer DataLayer { get { if (fDataLayer == null) { lock (lockObject) { if (fDataLayer == null) { fDataLayer = GetDataLayer(); } } } return fDataLayer; } } public static IDataLayer GetDataLayer() { XpoDefault.Session = null; string conn = MySqlConnectionProvider.GetConnectionString("", "root", "123456", "database"); XPDictionary dict = new ReflectionDictionary(); IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists); DevExpress.Xpo.Metadata.ReflectionClassInfo.SuppressSuspiciousMemberInheritanceCheck = true; dict.GetDataStoreSchema(typeof(Inscripcion).Assembly); IDataLayer dl = new ThreadSafeDataLayer(dict, store); return dl; } } public interface IXpoController { Session XpoSession { get; } } public class BaseXpoController : Controller,IXpoController { public BaseXpoController() { XpoSession = CreateSession(); } Session fXpoSession; public Session XpoSession { get { return fXpoSession; } private set { fXpoSession = value; } } protected virtual Session CreateSession() { return XpoHelper.GetNewSession(); } public interface IXpoController { Session XpoSession { get; } } } public class XpoModelBinder :DevExpressEditorsBinder { protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { IXpoController xpoController = controllerContext.Controller as IXpoController; if (xpoController == null) throw new InvalidOperationException("The controller does not support IXpoController interface :("); XPClassInfo classInfo = xpoController.XpoSession.GetClassInfo(modelType); ValueProviderResult result = bindingContext.ValueProvider.GetValue(classInfo.KeyProperty.Name); return result == null ? classInfo.CreateNewObject(xpoController.XpoSession) : xpoController.XpoSession.GetObjectByKey(classInfo, result.ConvertTo(classInfo.KeyProperty.MemberType)); } }

                                  Hi I would add something else I should do the project is more oriented to display data could tell me which of the two solutions should me more than they explain in this blog Details/K18525 I understood that the 2nd is offered by this but I am very clear also because doing ViewModel for each object (Classs) that I have if I explain more in detail you appreciate. But regardless of the application you want to do for now I also want to learn how to modify an object and save your changes and remove them.
                                  Help Me please!

                                • Uriah (DevExpress Support) 11.22.2013

                                  Hello Jurgen,
                                  Your code is correct. I have created a test project based on your description, and it works as expected. Attached is my test project for your reference.
                                  Would you please verify whether or not I used the same approach to edit data as you? If possible, please modify my test project to reproduce the problem, or send us your own project illustrating the issue. We will be happy to help you.

                                0 Solutions

                                Creation Date Importance Sort by