SourceProperty IsManaged

2 posts, 1 answers
  1. Dilshod
    Dilshod avatar
    23 posts
    Member since:
    Feb 2012

    Posted 15 Aug 2013 Link to this post

    Hi,
    I am using Fluent mapping to map my database tables. As others said I generated the code with FluentModel withard. What I want is to fire added event when new instance child element created and parent set to one of the existing object that tracked by ORM. I manually entered the IsManaged() in both sides, but couldn't make it work. Let me give you a better example:

    public class Customer
    {
    Id,
    Name,
    LastName,
    Contacts
    }

    public class Contact
    {
    Id,
    Name,
    LastName,
    Customer
    }

    What I want to do is create a new instance of contact then assign existing customer to it.

    ......
    Contact con = new Contact(){Id=1, Name = "Test", LastName = "Test"};
    con.Customer = existingCustomer;//this Customer is tracked by Telerik ORM
    ......

    After assigning existing customer to the contact ORM is not firing Added event.
    What I want is that Added event fired. Is it possible?

    Thanks,
  2. Answer
    Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 19 Aug 2013 Link to this post

    Hi Dilshod,

    You have one new Contact instance which is not tracked by the OpenAccessContext and one existing Customer instance which is tracked by the OpenAccessContext. So if you want to track a new object by the OpenAccessContext you have two options:
    1) Add the new object to the context.
    2) Create an association with an object which is tracked by the OpenAccessContext, but you should create the association from the side of the existing object.
     
    In your case you are trying to add the tracked instance to the new instance, but OpenAccessContext could not add the tracking functionality from this side. So to implement this scenario correctly, you should add the new Contact instance to the Contacts collection in the existing Customer instance:
    Contact con = new Contact(){Id=1, Name = "Test", LastName = "Test"};
    existingCustomer.Contacts.Add(con);

    I hope that helps.

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvementsshipped with this release.

  3. DevCraft banner
Back to Top