Note that there are some explanatory texts on larger screens.

plurals
  1. POGet SimpleDB attribute without looping through all attributes for an item
    primarykey
    data
    text
    <p>I would like to check an attribute using C# and SimpleDB without having to loop through all the attributes for a specific item.</p> <p>For example, if I have my domain: "MyDomain", and I have three attributes for an item (the item is: george@george.com).</p> <p>The three attributes are:</p> <p>Name<br/> Signup<br/> Contacts<br/></p> <p><br/> So for example this is my data:</p> <p>MyDomain (domain)<br/> &nbsp;&nbsp;george@george.com (item)<br/> &nbsp;&nbsp;&nbsp;&nbsp;George Doe (attribute)<br/> &nbsp;&nbsp;&nbsp;&nbsp;3-1-12 (attribute)<br/> &nbsp;&nbsp;&nbsp;&nbsp;mike@mike.com (attribute)<br/></p> <p><br/> <br/> The problem I am having is my code will loop through all 3 attributes in the george@george.com item.<br/> For example; when I run my code the output is:</p> <p>No Contacts Found<br/> No Contacts Found<br/> Contact: mike@mike.com<br/></p> <p>because my code is looping through all 3 attributes for the george@george.com item.<br/><br/></p> <p>I want to make my C# code only check the "Contacts" attribute and NOT loop through all the attributes for the george@george.com item.<br/><br/></p> <p>Can someone please show me how to do this?</p> <pre><code>AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(); String selectExpression = "Select * From MyDomain Where Email = 'george@george.com'"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { if (attribute.IsSetName()) { if (attribute.Name == "Contact") { if (attribute.IsSetValue()) { Console.WriteLine("Contact: {0}", attribute.Value); } } else { Console.WriteLine("No Contacts Found"); } } } } } </code></pre> <p><br/>I want it to directly just check the "Contacts" attribute to see if there is a value for it and not loop through all the attributes.</p> <p><br/> <br/></p> <p>Can someone show me a C# code example on how I would accomplish this? Thanks. <br/><br/><br/> EDIT: I still want to loop through all the "Contacts" in the "Contacts" attribute. I just don't want to loop through all the attributes that don't have the name "Contacts". The "Contacts" attribute can hold more than one contact and I still need to get all of those from the attribute.</p> <p>This line of code from Ken below:<br/><br/> string value = item.Attribute.First(a => a.Name == "Contact").Value<br/></p> <p>stops the looping of the different attributes, but it only returns 1 contact from the "Contacts" attribute even though there are more than 1 contact stored in the "Contacts" attribute.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload