Getting the full TableName

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Apr-2012 17:12:31   

I have a need to be able to build a Sql command which requires the full table name given an entity type but I can't seem to find an obvious way of accessing this.

PersistenceInfoProviderSingleton looked promising but is marked internal. If I use reflection to access this, can I get a table name from it?

Cheers Simon

PS I need to be able to clear a table and reset its identity and was thinking something along the lines of

LLCoolJHelper.ExecuteSql(adapter, string.Format("DBCC CHECKIDENT ([{0}], NORESEED);"), xxx);

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Apr-2012 19:09:50   

Which runtime library version are you using? And which template set are you using?

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 19-Apr-2012 08:16:41   

Walaa wrote:

Which runtime library version are you using? And which template set are you using?

It varies! (Just noticed that a library of mine was linked to a previous LLBLGen runtime version - fixed that and now find a whole load of interface signatures have changed so I'll have to fix them up cry )

SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll v3.5.0.0 is the one I want which is the latest for .NET 4 I believe?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Apr-2012 10:14:59   

roperty is caled SourceObjectName

In SelfServicing: you can find it in EntityField.

var tableName = OrderDetailFields.ProductId.SourceObjectName;

In Adapter:

IFieldPersistenceInfo info = adapter.GetFieldPersistenceInfo(OrderDetailFields.ProductId);
var tableName = info.SourceObjectName;
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 19-Apr-2012 12:28:24   

Sorry, should have said Adapter (but might change back to SelfServicing yet!)

Anyway, that method is protected. Argggh! You guys are hiding everything away from me!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 19-Apr-2012 15:53:19   

What method exactly? It might be available through the interfaces (IEntityCore, IEntity2), as we moved methods to the interfaces to clean up the public interface of entities.

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 20-Apr-2012 08:19:19   

GetFieldPersistenceInfo on DataAccessAdapterBase - its protected.

This seems to work:

    public partial class DataAccessAdapter
    {
        public string GetDatabaseTableName<T>() where T: EntityBase2
        {
            var firstField = GetFieldPersistenceInfos(typeof(T).Name)[0];

            return GetDbSpecificCreatorInstance().CreateObjectName(firstField);
        }
    }

Took we a while to work it out though!