locked
How to save dynamicly getting module object data in databaseEntities? RRS feed

  • Question

  • I'm getting object of module using System.Activator.CreateInstance(Type)

    I writed following code but that data not inserting into DB.

    public ActionResult Master(string id, FormCollection collection)
    {
    DBEntities ctx= new DBEntities();
    var DynamicObject=System.Activator.CreateInstance(Type);
    foreach(var fcollection in collection)
    {
    DynamicObject.GetType().GetProperty(fcollection.ToString()).SetValue(DynamicObject,collection[fcollection]);
    }
    ctx.DbSet(Type).AddObject(DynamicObject);
    ctx.SaveChanges();
    }


    So please help me How can i save dynamic model object data save into Database using EntityFramework?

    Friday, February 28, 2014 10:49 AM

All replies

  • Hello,

    What model do you used, Code first or others? Does this dynamic object has the correspondent table in the database?

    What is the “Type”? Is it the key word or just an instance object? What is the FormCollection?

    And for dynamic model in entity framework, there is a library for code first:

    http://dynamixdata.codeplex.com/

    For database or model first, we need to make sure the table already exists.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 3, 2014 5:13 AM