hi all, i have 2 classes (Master-Details), the "Order" and "OrderDetails" class, i am trying to add an Order details to the "Order.OrderDetails" EntitySet using reflection as the following:

  //1. create Instance of OrderDetails
     Xtensive.Storage.Entity typeInstance = (Xtensive.Storage.Entity)Activator.CreateInstance(Type.GetType(Assembly.CreateQualifiedName(AssemblyName, "OrderDetails")));

    //2. for each Property in OrderDetails set its value to a field from ASPXGridView

    foreach (PropertyInfo property in (Convert.ChangeType(typeInstance, Type.GetType(Assembly.CreateQualifiedName(AssemblyName, "OrderDetails")))).GetType().GetProperties().Where(tp => !tp.Name.Equals("Id")))
                        if (!e.NewValues.Contains(property.Name) || e.NewValues[property.Name] == null)

                        property.SetValue(typeInstance, Convert.ChangeType(e.NewValues[property.Name], property.PropertyType), null);

if (ObjectConnector.Object != null) // if an Instance of Order class exists add the OrderDetails created instance to it

                    //the Order Object
                    var EntityObject = Convert.ChangeType(ObjectConnector.Object, Type.GetType(Assembly.CreateQualifiedName(AssemblyName, "Order")));
                    //get the OrderDetails EntitySet
                    var EntityProperty = EntityObject.GetType().GetProperty("OrderDetails").GetValue(EntityObject, null);
                    //the Add method on the EntitySet
                    MethodInfo addEntitySetMethod = typeof(Xtensive.Storage.EntitySet<>).MakeGenericType(Type.GetType(Assembly.CreateQualifiedName(AssemblyName, "OrderDetails"))).GetMethod("Add");
                    //invoke the EntitySet's Add method passing the OrderDetails instance
                    addEntitySetMethod.Invoke(EntityProperty, new object[] { Convert.ChangeType(typeInstance, Type.GetType(Assembly.CreateQualifiedName(AssemblyName, "OrderDetails"))) });


OrderDetails instance created and assigned correctly to the Order instance but the session doesn't see the added OrderDetails (Session's transactions events don't fired), so it doesn't persist it (i am using Xtensive.Storage.Web.SessionManager to manage sessions), does i do somthing not supported or incorrect, or even should i do somthing else to save the OrderDetails instance.


asked Jan 19 '11 at 06:21

ahmad%20emad's gravatar image

ahmad emad

One Answer:

i don't now what is was the problem exactly, but when i used the solution mentioned by Peter Šulek at Bind EntitySet to GridView question, it works(so i think it may be due to binding grid view to an incorrect data source)

answered Jan 19 '11 at 14:00

ahmad%20emad's gravatar image

ahmad emad

Perfect. Thanks, Peter!

(Jan 19 '11 at 14:05) Dmitri Maximov Dmitri%20Maximov's gravatar image

My pleasure :-)

(Jan 19 '11 at 14:59) Peter Šulek Peter%20%C5%A0ulek's gravatar image

And this means that your code provided above works when you bind grid using LinqServerModeDataSource ?

(Jan 20 '11 at 01:43) Peter Šulek Peter%20%C5%A0ulek's gravatar image

sorry for being late in replay, yes it works but in addition to implementing selecting event on LinqServerModeDataSource, i also implemented Inserting, updating and deleting and some times the event not fired at the first time(for example i press new button on the grid or delete or even edit), i don't know why (i left it right now as i am working on a critical issue, but if its a bug in the data source or i am unable to find a solution, i believe that i can change the events to be on the Grid View it self )?

(Jan 24 '11 at 07:13) ahmad emad ahmad%20emad's gravatar image

Note: all the wok done dynamically from the code, as we are building a framework and we need the developer to just binds the grid to a property(Entity Set represents a details record) in an Entity (Master record)

(Jan 24 '11 at 07:26) ahmad emad ahmad%20emad's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA