Add isn't supported on a fields object which is part of an entity , EntityFields(2).Add("FieldName")

Posts   
 
    
guyronen
User
Posts: 26
Joined: 02-Mar-2021
# Posted on: 07-Mar-2021 22:12:56   

While addidnt a field to Entity, When Add Field to EntityFields(2).Add("FieldName") getting exception : Add isn't supported on a fields object which is part of an entity at SD.LLBLGen.Pro.ORMSupportClasses.EntityFieldsCore`1.Add(Object value) in C:\Myprojects\VS.NET Projects\LLBLGen Pro v5.7\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityFieldsCore.cs:line 1169

after migrating llblGen version from 3.5 to 5.7.2 code generated with 5.7.2 and runtime SD.LLBLGen.Pro.ORMSupportClasses version is 5.7.2 . the code adding a Filed to Entity worked on version 3.5 , why does nor support at 5.7.2 ?

Guy

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Mar-2021 05:58:23   

Hi Guy,

There is a breaking change in v4.0 about the way the fields are created and accessed internally, for better performance. I will quote the relevant text of the Migrating you code section at the documentation

How to work with the EntityFields(2) objects without using entity fields in an entity

If your code accesses the entity field objects in e.g. validators or auditors, instead of reading field properties, you can now access the values you need directly from the entity.Fields object through its IEntityFieldsCore interface, instead of obtaining the EntityField(2) object and access its properties. The reason you should use IEntityFieldsCore's methods instead of obtaining a field object from the Fields object is that entity objects no longer create entity field objects by default. They use a new internal object which is more efficient and allows faster entity materialization after a fetch. When you use entity.Fields[index] the Fields object will create a new field object for you on the fly, through which you can access the information you needed. However creating this field object is unnecessary.

In general this means you should use methods like entity.Fields.GetCurrentValue(index) instead of entity.Fields[index].CurrentValue. The latter still works, but creates an EntityField(2) object, the former doesn't. Please see for details about the IEntityFieldsCore interface, the LLBLGen Pro Runtime Framework Reference Manual (LLBLGenPro.RTL.ReferenceManual.chm).

Let us know if this answers your question. If not, please provide an exact code example so we can reproduce your behavior on our side and give a proper solution.

David Elizondo | LLBLGen Support Team
guyronen
User
Posts: 26
Joined: 02-Mar-2021
# Posted on: 18-Mar-2021 17:08:38   

Hi Daelmo,

this usage is not reading or trying to access fields for values . its Adding Fields to Entity object on runtime. with EntityFields(2).Add("FieldName"), its probably not the best practice but what its do is to expend an entity that fetched and add extension fields like sums and calculated fields to dislplay in grid . Fields.GetCurrentValue(index) will not help on this case as we need to add new fields to the entity. we were able to do it on previous version 3.5 and now i get that exception . any other way to do it , or any idea how i can expend an object from llblGen Entities for display on grid ? thank you will post the code on Sunday if needed.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 18-Mar-2021 20:26:35   

This is not supported on the entity level.

But for your case I suggest using using QuerySpec to compose your query and expressions, and project the resultSet. Please check this documentation page

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 19-Mar-2021 09:22:23   

You also could add a property in a partial class for that? As they're readonly, and based on the values in the entity, you don't need a value in the Fields object which is primarily for fields mapped to the table/view.

In theory you can extend it but it's not recommended. To do so, you have to use the factory to expand it before the entity is created. It's however cumbersome to do, and therefore it's best to use simple properties in a partial class to store the information you want to store.

Frans Bouma | Lead developer LLBLGen Pro
guyronen
User
Posts: 26
Joined: 02-Mar-2021
# Posted on: 20-Mar-2021 20:00:41   

Otis wrote:

You also could add a property in a partial class for that? As they're readonly, and based on the values in the entity, you don't need a value in the Fields object which is primarily for fields mapped to the table/view.

In theory you can extend it but it's not recommended. To do so, you have to use the factory to expand it before the entity is created. It's however cumbersome to do, and therefore it's best to use simple properties in a partial class to store the information you want to store.

ok, i will try using partial class. thank you .