Change ToDictionary to ToList

S

shapper

Hello,

I have the following code:

return _resources.Root.Elements("Resource").Select(r => new
Resource {
Id = (Int32)r.Element("Id"),
Constraints =
_resourcesConstraints.Root.Elements("ResourceConstraint")
.Where(rc => rc.Element("ResourceId").Value ==
r.Element("Id").Value)
.ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc =>
(String)rc.Element("Value")),
});

I want to change the Constraints property from IDictionary to
IList<Constraint>.

Each constraint object has 2 properties: Id and Value.

So I need to change the code line:
..ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc =>
(String)rc.Element("Value")),

ToList > and create a List of Constraint filling the Id and Value of
the constraint the same way.

How can I do this?

Thank You,
Miguel
 
S

shapper

Hello,

I have the following code:

      return _resources.Root.Elements("Resource").Select(r => new
Resource {
        Id = (Int32)r.Element("Id"),
        Constraints =
_resourcesConstraints.Root.Elements("ResourceConstraint")
          .Where(rc => rc.Element("ResourceId").Value ==
r.Element("Id").Value)
          .ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc =>
(String)rc.Element("Value")),
      });

I want to change the Constraints property from IDictionary to
IList<Constraint>.

Each constraint object has 2 properties: Id and Value.

So I need to change the code line:
.ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc =>
(String)rc.Element("Value")),

ToList > and create a List of Constraint filling the Id and Value of
the constraint the same way.

How can I do this?

Thank You,
Miguel

Solved it ... Needed only one more select.

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top