Associations to entities in a separate designer

Thread is closed for posting
4 posts, 0 answers
  1. Ron
    Ron avatar
    1 posts
    Member since:
    Jun 2012

    Posted 04 May 2011 Link to this post

    Trying to figure out if your product allows developers to break the object model up into more workable chunks rather than have the entire thing in one rlinq file. Entity Framework doesn't let you do it so looking at alternatives. Is it possible to create an association from an entity in one designer to an entity in another one? The toolbox option doesn't let you do it. I can't type anything into the Navigation section of an entity manually it doesn't appear. The .cs file says it'll be regenerated on changes as one would expect. Is there somewhere else we can try?

    Thank you,
  2. Alexander
    Alexander avatar
    727 posts

    Posted 05 May 2011 Link to this post

    Hi Ron,

    You will be able to merge two or more models into one, however, this will require some manual steps to be performed. I have attached a demo project which you can use for reference. Here are the details how I created it:
    1. Create a project and add the two domain models. While adding the models, on the last page of the wizard disable the Generate context option, the context has to be created manually.
    Note that a model should not contain any tables included in another model.
    2. Create a class deriving from OpenAccessContext (in the example this is MergedContext). The class content is very similar to the one you would get automatically generated. However, here you need to implement a method like the GetMetadataSource which merges the metadata from the two models into one. Once you have the method, initialize the static metadataSource variable with it.
    3. (Optional) For each class from the two models create an IQueryable<T> endpoint which can be used in linq queries. This step is optional because you can use the GetAll<T> method directly as well.

    This is everything to get the models merged, now you can work with any class from a single context instance. To set the relationships you can directly use the foreign key properties like Product.ProductSubcategoryID and change the value in order to manage the category this product belongs to.
    If you want to create navigation members like Product.Category of type ProductCategory, this is also possible but would require a lot more manual operations, including writing these properties manually and extending the OpenAccess metadata. This will have to be done for each association you want to create between classes from different rlinq files. If this is really what you are trying to achieve, just let me know and I will extend the example. I hope that helps.

    Kind regards,
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. rebtech
    rebtech avatar
    29 posts
    Member since:
    Jun 2007

    Posted 09 May 2011 Link to this post

    can you please expand this.  This is exactly what I need to do.  My database has 276 tables, and I still have about 40 more to add. I would like to split the diagrams up based on the schemas, and I will need to associate between them sometimes between several diagrams especially between the membership schema since members are related to just about all of them.
  4. Alexander
    Alexander avatar
    727 posts

    Posted 16 May 2011 Link to this post

    Hi rebtech,

    The updated demo is attached to this post. The main idea is that a fluent metadata source is used to merge the two rlinq models and define an association between the Product and ProductCategory classes. Please note that you will have to manually extend the two persistent classes and add the needed navigational properties (Product.Category and ProductCategory.Products). Additional associations can be defined in the PrepareMapping method in the same manner as it is done for the Product/ProductCategory association.

    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Back to Top