How to list dependent objects

Posts   
 
    
jimph
User
Posts: 63
Joined: 06-Jun-2013
# Posted on: 08-Jun-2013 18:21:36   

Hi, I would greatly appreciate some input to this critical issue please. We would like to use LLBLGen to generate csharp objects to access SQL Server (I am brand new to ORM).

Our database is generally large in size, hundreds of GBs, and consists of about 200 tables. What we need to do often is to quickly determine all objects that depend on/associated with a given object (using FKs) before performing certain action on the later (e.g., list all objects that will be deleted as the result of deleting a specific object).

My question is what I could do to quickly list all objects which depend on a specific object, using either csharp classes generated by LLBLGen or using NHibernate directly (most of the time we will be using the generated classes, except for this).

Many thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jun-2013 03:12:22   

If you are using LLBLGen Runtime, you can examine the dependent and depending on objects fetched. You also could inspect the relationships, here is a method that does that and you can use right away in your code:

private List<IEntity2> GetDependentEntities(IEntity2 entity)
{           
    var toReturn = new List<IEntity2>();
    var relations = entity.GetAllRelations();
    foreach (var rel in relations)
    {
        if (rel.GetPKEntityFieldCore(0).ActualContainingObjectName == entity.LLBLGenProEntityName)
        {
            var factory = EntityFactoryFactory.GetFactory((EntityType)Enum.Parse(typeof(EntityType), rel.GetFKEntityFieldCore(0).ActualContainingObjectName));
            toReturn.Add(factory.Create());
        }
    }
    return toReturn;
}

Is something like that what you are looking for?

David Elizondo | LLBLGen Support Team
jimph
User
Posts: 63
Joined: 06-Jun-2013
# Posted on: 11-Jun-2013 00:41:23   

Hi David, thank you for taking the time to help again.

I just saved the sample code you gave for references. Unfortunately our project is part of a larger project and for legacy issues we need to use NHibernate framework for the time being. Can you think of some other alternative(s) if that's possible at all please? Please discuss them all. While we would like to use what readily available like the code you gave, it is OK for us to do some extra works to make this possible (frankly I am completely sold on LLBLGen and just need to get over this hurdle which is important to what we do).

Many thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Jun-2013 08:09:03   

If I were you, I would check if there is already a NHibernate function/library that does that you are looking for (traverse the graph looking for dependencies).

Another think you can do is write your own LLBLGen template that generate a file that has methods that return the dependent objects given an entity. Approx pseudocode:

public static class GraphHelper
{
     public static List<string> GetDependentObjects(string root)
     {
          // do whatever you need here
     }

}

A possible list of steps to accomplish that could be:

  1. Create that class on your .net project. How would you like to generate such class? Then write a couple of methods that actually does the work.

  2. Then convert that into a template. You can look at the LLBLGen's built-in NHibernate templates to get an idea.

  3. Read the SDK documentation to get familiar with templates.

  4. Start with a very simple template, once it works, add code until you get the desired genrated code.

David Elizondo | LLBLGen Support Team