Problem reading an object inside another object

I have an object called ItalVinculacion, and inside it I have to read the content of ItalProduct, which is also an object, and obtain the values ​​of ItalEjeAplicacion and Type, which are objects within the product.

This is my code:

var autoId = Get<Guid>("IdAuto"); // ID del auto en ItalAutosNormalizados
var IdProduct = Get<Guid>("IdProduct"); // ID del producto de la nueva vinculación
var IdAxis = Get<Guid>("IdAxis"); 
var IdSubFamily = Get<Guid>("IdSubFamily"); 
 
if (IdProduct == Guid.Empty) {
    return false;
}
 
// Buscar vinculaciones existentes con el mismo auto
var vinculacionEsq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "ItalVinculacion");
vinculacionEsq.AddColumn("Id");
vinculacionEsq.AddColumn("ItalPriority");
 
// Acceder a las columnas del objeto relacionado ItalProduct usando alias
var ejeAplicacionColumn = vinculacionEsq.AddColumn("ItalProduct.ItalEjeAplicacion");
ejeAplicacionColumn.Name = "ItalEjeAplicacion";
 
var typeColumn = vinculacionEsq.AddColumn("ItalProduct.Type");
typeColumn.Name = "Type";
 
vinculacionEsq.Filters.Add(vinculacionEsq.CreateFilterWithParameters(FilterComparisonType.Equal, "ItalFleetID", autoId));
 
var existingVinculaciones = vinculacionEsq.GetEntityCollection(UserConnection);
int maxPriority = 0;
bool isDuplicateFound = false;
 
foreach (var vinculation in existingVinculaciones) {
    var existingEjeAplicacion = vinculation.GetTypedColumnValue<Guid>("ItalEjeAplicacion");
    var existingType = vinculation.GetTypedColumnValue<Guid>("Type");
 
    // Comparar GUIDs correctamente
    if (existingEjeAplicacion.Equals(IdAxis) && existingType.Equals(IdSubFamily)) {
        isDuplicateFound = true;
        var existingPriority = vinculation.GetTypedColumnValue<int>("ItalPriority");
 
        if (existingPriority == 0) {
            vinculation.SetColumnValue("ItalPriority", 1);
            Set("ItalPriority", 2);
        } else {
            Set("ItalPriority", existingPriority + 1);
            vinculation.SetColumnValue("ItalPriority", existingPriority + 1);
        }
 
        vinculation.Save();
        break; // Salir del bucle si se encuentra un duplicado
    }
 
    maxPriority = Math.Max(maxPriority, vinculation.GetTypedColumnValue<int>("ItalPriority"));
}
 
// Si no se encontró un duplicado, establece la prioridad de la nueva vinculación
if (!isDuplicateFound) {
    Set("ItalPriority", maxPriority + 1);
}
 
return true;

 

And this is the error:

Terrasoft.Common.ItemNotFoundException: Value "ItalProduct.ItalEjeAplicacion" was not found.

 

Like 0

Like

2 comments

Try using ItalEjeAplicacionId instead of ItalEjeAplicacion. This is the only assumption for now.

Oleg Drobina,

Thanks Oleg, I'll try it.

Show all comments