25
Views
2
Comments
How do i append current value from database to structure
Application Type
Traditional Web

Hey everyone
I have this aggerate, let call it GetAById
GetAById = 1 return 4 record with attribute BId = 1,2,3,4
I have a structure with about 20 attribute, how do i append those BId to the attribute in the structure?
Example
structure.attribute1 = 1
structure.attribute2 = 2
structure.attribute3 = 3
structure.attribute4 = 4
structure.attribute5 = null
...
structure.attribute20 = null
I try to use some assign like this
structure.attribute1 = GetAById.List[0].Entity.Bid
structure.attribute2 = GetAById.List[1].Entity.Bid 
...
structure.attribute20 = GetAById.List[19].Entity.Bid
The first 4 one work normal since they have data inside the DB, but to the fifth one it return an error "Index 4 is out of range"
I try to loop the aggerate but seem like there's no way to increase the structure number(Attribute 1->attribute2)
Thank you!

2017-11-21 02-24-59
Stephen Yeo Jie Hui

I think you may need to do a if/else check on GetAById.List.Length before trying to execute GetAById.List[X]. if X is < Length, proceed to assign, else don't try to assign. 

2021-01-28 10-02-59
Muhammad Mahmudul Hasan

@john cop 

Aggreged with Stephen.  I don't see any other option rather than adding explicit checking before assigning. Doing index operation is risky. 

 Assign only when 

GetAById .Length > x for structure.attribute1 = GetAById.List[x].Entity.Bid 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.