Entityfield as property

Posts   
 
    
Posts: 26
Joined: 23-May-2005
# Posted on: 23-May-2005 12:03:41   

We want to refer to an entity field as a property, so that the code is syntaxchecked when typed. We are new to LLBLGEN but a quick search didn't give us any clue if this feature already exists. See example below what we try to achieve.

Thanks in advance


dim CustRef as CustomersReference
if CustRef.CustomerNumber.DataType = ........ then .....

class definitions....


Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class CustomerReference

  Dim ce As New CustomerEntity

  Public ReadOnly Property CustomerNumber() As IEntityField
    Get
      Return ce.Fields("CustomerNumber")
    End Get
  End Property

  Public ReadOnly Property CustomerName() As IEntityField
    Get
      Return ce.Fields("CustomerName")
    End Get
  End Property

End Class

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-May-2005 20:52:16   

John wrote:

We want to refer to an entity field as a property, so that the code is syntaxchecked when typed. We are new to LLBLGEN but a quick search didn't give us any clue if this feature already exists. See example below what we try to achieve.

Thanks in advance


dim CustRef as CustomersReference
if CustRef.CustomerNumber.DataType = ........ then .....

class definitions....


Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class CustomerReference

  Dim ce As New CustomerEntity

  Public ReadOnly Property CustomerNumber() As IEntityField
    Get
      Return ce.Fields("CustomerNumber")
    End Get
  End Property

  Public ReadOnly Property CustomerName() As IEntityField
    Get
      Return ce.Fields("CustomerName")
    End Get
  End Property

End Class

Erm, 'ce' has a property CustomerNumber (and CustomerName) simple_smile Every entity field is available as a property.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 26
Joined: 23-May-2005
# Posted on: 23-May-2005 21:16:42   

OK, but this is the value of the field. i want the entity instance itself as a property

so ce.customername gives the contens of the field

I'm looking for the instance itself, so i can use code like this to get the datatype property

cd.customername.datatype or cd.customername.columnname

i do not like to use the fieldname as a string

ce.Fields("customername").DataType()

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 23-May-2005 21:21:46   

John wrote:

OK, but this is the value of the field. i want the entity instance itself as a property

so ce.customername gives the contens of the field

I'm looking for the instance itself, so i can use code like this to get the datatype property

cd.customername.datatype or cd.customername.columnname

i do not like to use the fieldname as a string

ce.Fields("customername").DataType()

Hmmm...I'm not sure you could do this without compromising the databinding features of the entities...

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-May-2005 21:47:22   

John wrote:

OK, but this is the value of the field. i want the entity instance itself as a property

so ce.customername gives the contens of the field

I'm looking for the instance itself, so i can use code like this to get the datatype property

cd.customername.datatype or cd.customername.columnname

i do not like to use the fieldname as a string

ce.Fields("customername").DataType()

Aha. simple_smile

Ok, you can do: Type t = cd.CustomerName.GetType();

As DataType is the .NET type of the field, which is the same type as the property. Also, if you want the types, you can use reflection.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 26
Joined: 23-May-2005
# Posted on: 23-May-2005 23:03:56   

I'm afraid i don't understand what the follwing code would harm...

Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class CustomerReference

Dim ce As New CustomerEntity

Public ReadOnly Property CustomerNumber() As IEntityField Get Return ce.Fields("CustomerNumber") End Get End Property

Public ReadOnly Property CustomerName() As IEntityField Get Return ce.Fields("CustomerName") End Get End Property

End Class

But i was wondering if this is already part of LLBLGEN.

We are converting our framework to .NET and want to couple for example a textbox to a field from the LLBLGEN collection. it would be nice to use properties in stead of de string for accessing the fields. So can this be done or do i have to code this myself.

Posts: 26
Joined: 23-May-2005
# Posted on: 23-May-2005 23:07:30   

Ok, you can do: Type t = cd.CustomerName.GetType();

As DataType is the .NET type of the field, which is the same type as the property. Also, if you want the types, you can use reflection.


It's not only the datatype i'm interested. I just want to refer to the entity by a synatax checked prooperty name instead of accessing it by fieldname as string.

If i make typing errors, it wil result in runtime errors. this is what i want to avoid.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-May-2005 23:35:29   

I'm not really following what you're trying to achieve, sorry. simple_smile

Do you want to access the entity's fields in a syntax checked way? -> use the properties on the entity. If you want to access field specific properties, you can do:

entity.Fields[(int)entityFieldIndex.FieldName].property

which is syntax checked, because you use the enum so typo's are caught by the compiler:

Type t = customer.Fields[(int)CustomerFieldIndex.CompanyName].DataType;

Frans Bouma | Lead developer LLBLGen Pro
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 23-May-2005 23:46:36   

John wrote:

It's not only the datatype i'm interested. I just want to refer to the entity by a synatax checked prooperty name instead of accessing it by fieldname as string.

If i make typing errors, it wil result in runtime errors. this is what i want to avoid.

Are you using adapter or self-servicing?

For both, every Entity has a syntax-checked (and typed!) property for every field in its underlying table or view.

However, if you are using adapter, and are trying to access entity property names off of an entity collection, you either need to use the field's string name (usually not the best method) or cast the entity to a specific entity type before you access the fields by property name (usually the preferred method).

Self-servicing entity collections are typed.

Outside of the possibility of your difficulties coming from EntityCollections (which the above text is meant to remedy), your questions don't make a lot of sense. The functionality you are asking for should be available out of the box.

Posts: 26
Joined: 23-May-2005
# Posted on: 24-May-2005 08:50:45   

Otis wrote:

I'm not really following what you're trying to achieve, sorry. simple_smile

Do you want to access the entity's fields in a syntax checked way? -> use the properties on the entity. If you want to access field specific properties, you can do:

entity.Fields[(int)entityFieldIndex.FieldName].property

which is syntax checked, because you use the enum so typo's are caught by the compiler:

Type t = customer.Fields[(int)CustomerFieldIndex.CompanyName].DataType;

Yes i think this is what i was looking for! I will try this. Thanks.

Posts: 26
Joined: 23-May-2005
# Posted on: 24-May-2005 10:51:18   

Otis wrote:

I'm not really following what you're trying to achieve, sorry. simple_smile

Do you want to access the entity's fields in a syntax checked way? -> use the properties on the entity. If you want to access field specific properties, you can do:

entity.Fields[(int)entityFieldIndex.FieldName].property

which is syntax checked, because you use the enum so typo's are caught by the compiler:

Type t = customer.Fields[(int)CustomerFieldIndex.CompanyName].DataType;

Still one remark about it. Is it possible to generate these fields as a seperate class with properties. Seems more natural to me. I'm quite new to LLBLGEN but i read something about templates. Can they do this job for me or do you have another solution. I really like to have a shortcut to like this:

type t = customer.CompanyName.DataType

Posts: 26
Joined: 23-May-2005
# Posted on: 24-May-2005 10:58:55   

psandler wrote:

John wrote:

It's not only the datatype i'm interested. I just want to refer to the entity by a synatax checked prooperty name instead of accessing it by fieldname as string.

If i make typing errors, it wil result in runtime errors. this is what i want to avoid.

Are you using adapter or self-servicing?

For both, every Entity has a syntax-checked (and typed!) property for every field in its underlying table or view.

However, if you are using adapter, and are trying to access entity property names off of an entity collection, you either need to use the field's string name (usually not the best method) or cast the entity to a specific entity type before you access the fields by property name (usually the preferred method).

Self-servicing entity collections are typed.

Outside of the possibility of your difficulties coming from EntityCollections (which the above text is meant to remedy), your questions don't make a lot of sense. The functionality you are asking for should be available out of the box.

thanks for your repsonse:

I use Self-servicing and yes the fields are available (but these are the values). I want to reference the field entity by itself. We are converting our development framework from Progress to .NET and want to make a reference in our program from a screen field to a entity field. Here we would like to refer to the entify by its name instead of the index or string. suppose: field.reference = entity.field. In our framework we could then take special actions if for instance this datatype is date etc. or do other things.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-May-2005 16:19:48   

John wrote:

Otis wrote:

I'm not really following what you're trying to achieve, sorry. simple_smile

Do you want to access the entity's fields in a syntax checked way? -> use the properties on the entity. If you want to access field specific properties, you can do:

entity.Fields[(int)entityFieldIndex.FieldName].property

which is syntax checked, because you use the enum so typo's are caught by the compiler:

Type t = customer.Fields[(int)CustomerFieldIndex.CompanyName].DataType;

Still one remark about it. Is it possible to generate these fields as a seperate class with properties. Seems more natural to me. I'm quite new to LLBLGEN but i read something about templates. Can they do this job for me or do you have another solution. I really like to have a shortcut to like this:

type t = customer.CompanyName.DataType

That can only be done if 'CompanyName' 's value is not a value type as .NET's types, but a custom object. Because the properties return value types / .NET types, the properties they have are the ones these valuetypes/.NET types have. You can of course generate a class for that, though with the fieldindex you get the same thing. simple_smile

Frans Bouma | Lead developer LLBLGen Pro