Database Column name

Posts   
 
    
fcastell
User
Posts: 13
Joined: 10-Jan-2008
# Posted on: 15-Feb-2008 21:47:09   

Hello,

Is it possible to get the database column name of an EntityField2?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Feb-2008 23:01:21   

Hi fcastell,

  1. Extend _DataAccessAdapter _class via a partial class (or derive a class from DataAccessAdapter), create a method which receive a IEntityField2, then retrieve the _IFieldPersistenceInfo _and return the whole object or just the column name.
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace <yourDatabaseSpecificNamespace>
{   
    // I'm using a partial class, but you can create an inherited class
    public partial class DataAccessAdapter
    {
             public string GetSourceColumnName(IEntityField2 field)
             {
                 // access the protected method to retrieve the field's info
                 IFieldPersistenceInfo fieldInfo = GetFieldPersistenceInfo(field);

                // return the name of the source column
                return fieldInfo.SourceColumnName;
            }       
    }
}
  1. Use the method you just created and pass a _IEntityField2 _to it. You can access the fields via <YourNamespace>.HelperClasses.<SomeEntity>Fields.<SomeField>.
DataAccessAdapter adapter = new DataAccessAdapter();
string someColumName = adapter.GetSourceColumnName(CustomerFields.CompanyName); 
David Elizondo | LLBLGen Support Team
fcastell
User
Posts: 13
Joined: 10-Jan-2008
# Posted on: 17-Feb-2008 00:21:27   

Thanks David for your answer, it is exactly what I need.

Fabien

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 10-Mar-2009 09:13:38   

Dim fieldInfo As IFieldPersistenceInfo = SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetFieldPersistenceInfo(oDataType)

when i try the above it says the method is protected?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Mar-2009 09:21:55   

Yes this method is protected.

// I'm using a partial class, but you can create an inherited class public partial class DataAccessAdapter { public string GetSourceColumnName(IEntityField2 field) { // access the protected method to retrieve the field's info IFieldPersistenceInfo fieldInfo = GetFieldPersistenceInfo(field);

            // return the name of the source column
            return fieldInfo.SourceColumnName;
        }       
}

You should expose it by either wrappng it with another method as shown in the above example, or by inheriting from the DataAccessAdapter.

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 10-Mar-2009 10:37:56   

converted the above example yto vb but getting error

' I'm using a partial class, but you can create an inherited class
Partial Public Class DataAccessAdapter
    Public Function GetFieldInfo(ByVal field As IEntityField2) As String
        ' access the protected method to retrieve the field's info
        Dim fieldInfo As IFieldPersistenceInfo = GetFieldPersistenceInfo(field)***Error Name undeclared 

        ' return the name of the source column
        Return fieldInfo.SourceColumnName
    End Function
End Class
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 10-Mar-2009 22:28:43   

You need to inherit from DataAccessAdapter rather than extend it with a partial class.


Partial Public Class DataAccessAdapterExtend
    Inherits DataAccessAdapter

    Public Function GetFieldInfo(ByVal field As IEntityField2) As String
        ' access the protected method to retrieve the field's info
        Dim fieldInfo As IFieldPersistenceInfo = GetFieldPersistenceInfo(field)

        ' return the name of the source column
        Return fieldInfo.SourceColumnName
    End Function
End Class

Matt