Determine catalog name per entity

Posts   
 
    
CowHills
User
Posts: 47
Joined: 14-Mar-2007
# Posted on: 17-Jan-2014 17:07:48   

Is there a possibility to determine the catalog name a entity belongs to.

LLBL version 4.0

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Jan-2014 05:44:41   

Yes, there is a way. From your previous threads I assume that you are using Adpater templaset. So, create a class file in your DBSpecific project and write this:

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace <YourRootNameSpace>.DatabaseSpecific
{
    public partial class DataAccessAdapter
    {
        public string GetCatalogNameForEntity(IEntity2 entity)
        {
            return PersistenceInfoProviderSingleton.GetInstance().GetAllFieldPersistenceInfos(entity)[0].SourceCatalogName;             
        }
    }
}

... and the usage:

[TestMethod]
public void GetCatalogName()
{
    string catalog = new DataAccessAdapter().GetCatalogNameForEntity(new CustomerEntity());
    Assert.AreEqual("Northwind", catalog);
}
David Elizondo | LLBLGen Support Team
CowHills
User
Posts: 47
Joined: 14-Mar-2007
# Posted on: 19-Jan-2014 23:09:59   

Thanks for this solution. I found a different solution but it acts more or less in the same way:


var entity = new CustomerInfoEntity()
var field = entity.Fields[0];

var catalogName = ORMapper.Utils.DatabasePersistenceInfo.GetFieldPersistenceInfo(field).SourceCatalogName;