Name of database field mapped on entity field

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 10-Oct-2009 18:01:12   

Is there a way to get at runtime the name of the db field mapped on the entity field ??

EDIT:

CustomerEntity e = new CustomerEntity();

e.Fields[0].Name <== this gives the entity's field name NOT the name of the source DB field

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 11-Oct-2009 11:16:48   

In selfservicing, it's in the field, in adapter, you need to obtain the fieldpersistence info, what do you use, adapter or selfservicing?

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 11-Oct-2009 14:28:12   

I am using Adapter (ofcourse simple_smile )... I will check this fieldpersistence object but any tips are always welcomed simple_smile

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 11-Oct-2009 16:02:05   

I found the following in DADBSpecific

    internal class PersistenceInfoProviderCore : PersistenceInfoProviderBase
    {
        /// <summary>Initializes a new instance of the <see cref="PersistenceInfoProviderCore"/> class.</summary>
        internal PersistenceInfoProviderCore()
        {
            Init();
        }

        /// <summary>Method which initializes the internal datastores with the structure of hierarchical types.</summary>
        private void Init()
        {
            base.InitClass((1 + 0));
            InitUidictionaryEntityMappings();

        }


        /// <summary>Inits UidictionaryEntity's mappings</summary>
        private void InitUidictionaryEntityMappings()
        {
            base.AddElementMapping( "UidictionaryEntity", "winUI", @"Default", "UIDictionary", 3 );
            base.AddElementFieldMapping( "UidictionaryEntity", "SourceFormName1", "SourceFormName", false, (int)OleDbType.VarWChar, 75, 0, 0, false, "", null, typeof(System.String), 0 );
            base.AddElementFieldMapping( "UidictionaryEntity", "EntityName1", "EntityName", false, (int)OleDbType.VarWChar, 75, 0, 0, false, "", null, typeof(System.String), 1 );
            base.AddElementFieldMapping( "UidictionaryEntity", "TargetFormName1", "TargetFormName", true, (int)OleDbType.VarWChar, 75, 0, 0, false, "", null, typeof(System.String), 2 );
        }

    }

In the LLBL project file I changed the property name of the field sourceFormName to sourceFormName1 so to track where to find the mapping

Is it true to assume that in the following code:

base.AddElementFieldMapping( "UidictionaryEntity", "SourceFormName1", "SourceFormName", false, (int)OleDbType.VarWChar, 75, 0, 0, false, "", null, typeof(System.String), 0 );

"SourceFormName1" is the entity field's property name and "SourceFormName" is the name of the DB table field mapped on that entity field?

If that is truly the case, how can I obtain this info? If I try the following

var x = FieldInfoProviderSingleton.GetInstance().GetFieldInfo("UidictionaryEntity", (int)fieldIndex);

(where field index is the index of the field I need) and inspect the properties of x, which property will give me "SourceFormName" instead of "SourceFormName1" ??

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Oct-2009 21:27:30   

Here is the snippet to figure out the source column name for a given IEntityField2: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12530&StartAtMessage=0&#69571

David Elizondo | LLBLGen Support Team
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 11-Oct-2009 23:15:03   

Right on the money.. works like a charm... Thank you daelmo

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 12-Oct-2009 17:37:12   

Hello,

Is it possible to get the database Table name of an Entity2 ?

Like CustomerEntity ==> Customer <==this is table name from Database

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 12-Oct-2009 17:41:47   

Exactly the same as above but using SourceObjectName property instead of SourceColumnName.

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 12-Oct-2009 17:46:45   

Walaa.. thanks for reply, but this is the table name of field

what i want, Passing entity2 and get its table name

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Oct-2009 04:00:12   

Here is an example:

namespace <YourRootNamespace>.DatabaseSpecific
{
    public partial class DataAccessAdapter
    {   
    
        public string GetSourceTableName(IEntity2 entity)
        {
            return this.GetFieldPersistenceInfos(entity)[0].SourceObjectName;
        }       

    }
}
David Elizondo | LLBLGen Support Team
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Oct-2009 09:35:55   

To elaborate more on this: An entity can have fields mapped to more tha one database table, as in the case of inheritance, that's why the Field or FieldPersistenceInfo is the structure/class holding the mapped table name.

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 13-Oct-2009 09:48:02   

so Walaa.. ignoring the inheritance angle and assuming all my entities are mapped one-to-one to tables/views, I can safely assume all the entity fields have the same DB table mapping

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Oct-2009 10:13:55   

Sure.

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 13-Oct-2009 10:19:53   

Thank Walaa and thank you all for the great input..this forum continues to be as useful as ever

AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 27-Nov-2012 18:29:52   

I have a question related to this thread. I have entity that is a subtype. How can I retrieve source table name at run time? GetFieldPersistenceInfos() returns empty array. I see generated code calling this.AddElementMapping() on the entity that is a subtype, I just don't know how to get to the table name. I'm using version 3.1.

Thank you.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 27-Nov-2012 19:07:10   

Please open a new thread for your question. (hint: check forum guidelines)

Thanks.