This is a migrated thread and some comments may be shown as answers.

SourceProperty IsManaged

1 Answer 66 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dilshod
Top achievements
Rank 1
Dilshod asked on 15 Aug 2013, 01:39 PM
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,

1 Answer, 1 is accepted

Sort by
0
Accepted
Boris Georgiev
Telerik team
answered on 19 Aug 2013, 08:56 AM
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.

Tags
Data Access Free Edition
Asked by
Dilshod
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or