I have the following object declaration:
DatabaseTableElm exportTable = new DatabaseTableElm()
{
Columns = columnCt ,
Keys = {
new DatabaseKeyCt()
{
/* this way of setting columns works */
Columns = { new DatabaseKeyColumnCt() { Name = "ObjectId", SortOrder = SortOrderEnum.Descending } },
Type = DatabaseKeyTypeEnum.Primary
},
new DatabaseKeyCt()
{
/* this way of setting columns does not work */
Columns = list.Keys.Select(x => new DatabaseKeyColumnCt() { Name = x, SortOrder = SortOrderEnum.Ascending } ).ToList(),
Type = DatabaseKeyTypeEnum.Unique
}
},
Name = "test",
Schema = "dbo",
Temporal = true
};
Columns is a property defined in class DatabaseKeyCt like
public List<VaultSchemaObjects.Tns.DatabaseKeyColumnCt> Columns { get; } = new List<VaultSchemaObjects.Tns.DatabaseKeyColumnCt>();
At the first comment you can see that despite being a get only property, I can still initialize it with an array of "static" values. At the second comment I try to do the same but now with a list of objects. But at that point I get an error saying that columns is readonly.
My assumption is that at the first comment the array is accepted as some kind initial collection of the list. But At the second comment it thinks I am trying to assign a new list and it fails.
I cannot change class so the solution of adding a setter to the Columns property is not valid.
Can the line at the second comment be fixed so I can populate the list from my linq expression?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…