Trouble Querying/Parsing XML In SQL Server 2014 - xml-parsing

Given this XML:
<DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:refId="Package" DTS:CreationDate="11/29/2011 1:47:31 AM" DTS:CreationName="Microsoft.Package" DTS:CreatorComputerName="MyComp" DTS:CreatorName="dbo\administrator" DTS:Description="SSIS Package Description" DTS:DTSID="{3BBFC5EF-56B7-44D3-A078-7967F8C6149B}" DTS:EnableConfig="True" DTS:ExecutableType="Microsoft.Package" DTS:LastModifiedProductVersion="12.0.2000.8" DTS:LocaleID="1033" DTS:MaxErrorCount="0" DTS:ObjectName="pkgName" DTS:VersionBuild="69" DTS:VersionGUID="{86355AA2-4B44-46F3-8F21-2B4EF047044D}">
<DTS:Property DTS:Name="PackageFormatVersion">8</DTS:Property>
<DTS:ConnectionManagers>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[filename.txt]" DTS:CreationName="FLATFILE" DTS:DTSID="{C2C47A96-2F93-4B27-8F75-EEAB49BFB993}" DTS:ObjectName="filename.txt">
<DTS:ObjectData>
<DTS:ConnectionManager DTS:Format="RaggedRight" DTS:LocaleID="1033" DTS:HeaderRowDelimiter="_x000D__x000A_" DTS:RowDelimiter="" DTS:TextQualifier="_x003C_none_x003E_" DTS:CodePage="1252" DTS:ConnectionString="D:\batch\dataFiles\filename.txt">
<DTS:FlatFileColumns>
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="9" DTS:MaximumWidth="9" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="ssn" DTS:DTSID="{D5EE68E0-149C-4EF9-A521-09D0E5F2542F}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="3" DTS:MaximumWidth="3" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="component" DTS:DTSID="{DBCF7A29-A2E3-42B6-A04F-956DBAC79F8B}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="8" DTS:MaximumWidth="8" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="component_date" DTS:DTSID="{58D32551-9D64-4A58-96F7-B7892450581E}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="20" DTS:MaximumWidth="20" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_name" DTS:DTSID="{BA178333-E8AB-49EF-838E-33D344857EDB}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="25" DTS:MaximumWidth="25" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_street" DTS:DTSID="{3A08B6F4-5A04-4280-A1A7-A3F21730BC8C}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="18" DTS:MaximumWidth="18" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_city" DTS:DTSID="{CD9D7AAF-C664-4AB8-AD2A-ECE88F1C0900}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="2" DTS:MaximumWidth="2" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_state" DTS:DTSID="{60DE0571-2E94-4FD7-8A97-EEB7AE1F4515}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="9" DTS:MaximumWidth="9" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_zip" DTS:DTSID="{2727BECF-749F-46B9-BF1D-9B0081BECA62}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="7" DTS:MaximumWidth="7" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="emp_phone" DTS:DTSID="{D5B7BB28-913C-4B38-B849-23431C2BE932}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="25" DTS:MaximumWidth="25" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="work_type" DTS:DTSID="{9E321BD3-A960-47A0-9A29-972053449516}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="2" DTS:MaximumWidth="2" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="hours_per_week" DTS:DTSID="{BA0C9BC9-C295-4460-A2A6-2DF0D7D254A6}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="7" DTS:MaximumWidth="7" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="wages" DTS:DTSID="{34EC742F-5133-4DEC-A568-3092A23DCA79}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="8" DTS:MaximumWidth="8" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="start_date" DTS:DTSID="{AC63CADC-2E7A-43C9-91C4-F02F24AA19A0}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="1" DTS:MaximumWidth="1" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="parm_employment" DTS:DTSID="{5DDFBA20-D527-4FFA-88D1-2E996D7997A2}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="1" DTS:MaximumWidth="1" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="P_T_employment" DTS:DTSID="{A35AB03E-9323-4CA7-B7D7-3E4C7DD7A2B2}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnDelimiter="" DTS:ColumnWidth="20" DTS:MaximumWidth="20" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="employee_name" DTS:DTSID="{5C5079CB-48F8-415A-9DB3-8BE8CFF156BB}" DTS:CreationName="" />
<DTS:FlatFileColumn DTS:ColumnType="Delimited" DTS:ColumnDelimiter="_x000D__x000A_" DTS:MaximumWidth="4" DTS:DataType="129" DTS:TextQualified="True" DTS:ObjectName="local_office" DTS:DTSID="{3BED2123-DF68-43C9-B777-5A7282F36057}" DTS:CreationName="" />
</DTS:FlatFileColumns>
</DTS:ConnectionManager>
</DTS:ObjectData>
</DTS:ConnectionManager>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[Configuration Connection]" DTS:CreationName="OLEDB" DTS:DTSID="{05edc4ae-ddea-49c9-a430-4d9a3119ec7c}" DTS:ObjectName="Configuration Connection">
<DTS:ObjectData>
<DTS:ConnectionManager DTS:ConnectionString="Data Source=(local);Initial Catalog=SSISConfigs;Provider=SQLNCLI11;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-Package-{E0462A98-CA65-44B0-A74B-90AE4E5B1EEE}deswcrmssqlq1.server.SSISConfigs;" />
</DTS:ObjectData>
</DTS:ConnectionManager>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[Production]" DTS:CreationName="OLEDB" DTS:DTSID="{E06BCA4D-7F8B-41E0-848E-7DCD47731D44}" DTS:ObjectName="Production">
<DTS:ObjectData>
<DTS:ConnectionManager DTS:ConnectionString="Data Source=(local);Initial Catalog=production;Provider=SQLNCLI11;Integrated Security=SSPI;Auto Translate=false;Application Name=SSIS-Package-{E06BCA4D-7F8B-41E0-848E-7DCD47731D44}(local) production;" />
</DTS:ObjectData>
</DTS:ConnectionManager>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[SMTP Connection Manager]" DTS:CreationName="SMTP" DTS:DTSID="{1445d2e3-744c-46ed-809f-ab9f5c30eb0e}" DTS:ObjectName="SMTP Connection Manager">
<DTS:ObjectData>
<SmtpConnectionManager ConnectionString="SmtpServer=mail.myserver.com;UseWindowsAuthentication=True;EnableSsl=False;" />
</DTS:ObjectData>
</DTS:ConnectionManager>
</DTS:ConnectionManagers>
<DTS:Configurations>
<DTS:Configuration DTS:ConfigurationString=""Configuration Connection";"[dbo].[SSIS Configurations]";"package";" DTS:ConfigurationType="7" DTS:CreationName="" DTS:DTSID="{FEA2D0C6-ED02-451D-9038-8E63A555E1D1}" DTS:ObjectName="Configuration 2" />
</DTS:Configurations>
<DTS:Variables>
<DTS:Variable DTS:CreationName="" DTS:DTSID="{4B742A03-0599-471D-B8D1-E444DD74FCF8}" DTS:IncludeInDebugDump="2345" DTS:Namespace="User" DTS:ObjectName="FTPFile">
<DTS:VariableValue DTS:DataType="8">\\myserver\c$\cygwin64\path\filename.txt</DTS:VariableValue>
</DTS:Variable>
</DTS:Variables>
<DTS:Executables>
<DTS:Executable DTS:refId="Package\Delete Existing File from FTP Server" DTS:CreationName="Microsoft.FileSystemTask" DTS:Description="File System Task" DTS:DTSID="{EB57CB73-8CAD-4157-87F6-66E84EE9AA4C}" DTS:ExecutableType="Microsoft.FileSystemTask" DTS:LocaleID="-1" DTS:ObjectName="Delete Existing File from FTP Server" DTS:TaskContact="File System Task;Microsoft Corporation; Microsoft SQL Server 2008 R2; © 2007 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1" DTS:ThreadHint="0">
<DTS:Variables />
<DTS:ObjectData>
<FileSystemData TaskOperationType="DeleteFile" TaskSourcePath="User::FTPFile" TaskIsSourceVariable="True" />
</DTS:ObjectData>
</DTS:Executable>
<DTS:Executable DTS:refId="Package\Extract data to file" DTS:CreationName="Microsoft.Pipeline" DTS:DelayValidation="True" DTS:DTSID="{3E3B3666-30B4-4EAE-B962-72775E7A5A36}" DTS:ExecutableType="Microsoft.Pipeline" DTS:FailPackageOnFailure="True" DTS:LocaleID="-1" DTS:ObjectName="Extract data to file" DTS:TaskContact="Performs high-performance data extraction, transformation and loading;Microsoft Corporation; Microsoft SQL Server v10; (C) 2007 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1">
<DTS:Variables />
<DTS:ObjectData>
<pipeline BLOBTempStoragePath="" bufferTempStoragePath="" defaultBufferSize="3145728" version="1">
<components>
<component refId="Package\Extract data to file\Destination - file_export_txt" componentClassID="Microsoft.FlatFileDestination" contactInfo="Flat File Destination;Microsoft Corporation; Microsoft SqlServer v10; (C) Microsoft Corporation; All Rights Reserved; http://www.microsoft.com/sql/support;0" description="Flat File Destination" localeId="1033" name="Destination - file_export_txt" validateExternalMetadata="False">
<properties>
<property dataType="System.Boolean" description="Specifies whether the data will overwrite or append to the destination file." name="Overwrite">true</property>
<property dataType="System.Null" description="Specifies the text to write to the destination file before any data is written." expressionType="Notify" name="Header" />
</properties>
<connections>
<connection refId="Package\Extract data to file\Destination - file_export_txt.Connections[FlatFileConnection]" connectionManagerID="Package.ConnectionManagers[filename.txt]" connectionManagerRefId="Package.ConnectionManagers[filename.txt]" name="FlatFileConnection" />
</connections>
...
What do I need to use as far as nodes to get the value for connectionManagerRefId (second line from the bottom)?
I'm trying:
WITH XMLNAMESPACES ('www.microsoft.com/SqlServer/Dts' AS DTS) -- declare XML namespaces
SELECT t.e.value('#DTS:DTSID','varchar(100)') AS DTSID,
t.e.value('#DTS:ObjectName','varchar(100)') AS ObjectName,
ex.st.value('#DTS:refId','varchar(max)') AS StepID,
ex.st.value('#DTS:ObjectName','varchar(max)') AS StepName,
ex.st.value('#DTS:Description','varchar(max)') AS StepDesc,
cx.cn.value('(connectionManagerRefId)[1]','varchar(max)') AS StepConn
FROM #SSISPackagesList PackageXML
CROSS APPLY PackageXMLContent.nodes('DTS:Executable') t(e)
OUTER APPLY t.e.nodes('DTS:Executables/DTS:Executable') AS ex(st) --Control flow steps
OUTER APPLY ex.st.nodes('DTS:ObjectData/pipeline/components/component/connections/connection') cx(cn);
Where #SSISPackagesList.PackageXMLContent contains the XML to be searched. This query successfully returns values for every column EXCEPT StepConn. I'm fairly new to XML and extracting data from it, so I'm guessing this has something to do with missing [1] values, but I'm not not quite sure how. Thank you for your assistance solving this; any explanation you can provide for my future knowledge would also be greatly appreciated.

Looks like it was just a small syntax error that needed fixing (see below):
SELECT t.e.value('#DTS:DTSID','varchar(100)') AS DTSID,
t.e.value('#DTS:ObjectName','varchar(100)') AS ObjectName,
ex.st.value('#DTS:refId','varchar(max)') AS StepID,
ex.st.value('#DTS:ObjectName','varchar(max)') AS StepName,
ex.st.value('#DTS:Description','varchar(max)') AS StepDesc,
cx.cn.value('#connectionManagerRefId[1]','varchar(max)') AS StepConn
FROM #SSISPackagesList PackageXML
CROSS APPLY PackageXMLContent.nodes('DTS:Executable') t(e)
OUTER APPLY t.e.nodes('DTS:Executables/DTS:Executable') AS ex(st) --Control flow steps
OUTER APPLY ex.st.nodes('DTS:ObjectData/pipeline/components/component/connections/connection') cx(cn)
Property name needed an '#' in front of it.

Related

Custom UserDetailsService in spring-security

I cant proceed further into my project because of an strange error. I am trying to implement spring-security and spring data JPA for my application, which exposes only REST api.
Now, when I am trying to implement my custom UserDetailsService class, as mentioned below, the parameter username in method loadUserByUsername is not the username I am passing as a POST request parameter, rather its the client_id parameter.
Can someone please suggest as what am I doing wrong?
public class CustomUserDetailsService implements UserDetailsService {
private ClientDetailsService clientDetailsService;
private String emptyPassword = "";
public CustomUserDetailsService() {
}
public CustomUserDetailsService(ClientDetailsService clientDetailsService) {
this.clientDetailsService = clientDetailsService;
}
private List<GrantedAuthority> getAuthorities(String role) {
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
authList.add(new SimpleGrantedAuthority("ROLE_USER"));
// you can also add different roles here
// for example, the user is also an admin of the site, then you can add
// ROLE_ADMIN
// so that he can view pages that are ROLE_ADMIN specific
if (role != null && role.trim().length() > 0) {
if (role.equals("admin")) {
authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
}
}
return authList;
}
#Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
ClientDetails clientDetails = clientDetailsService
.loadClientByClientId(username);
String clientSecret = clientDetails.getClientSecret();
if (clientSecret == null || clientSecret.trim().length() == 0) {
clientSecret = emptyPassword;
}
return new User(username, clientSecret, clientDetails.getAuthorities());
}
}
My spring-security configuration is as following:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd ">
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<custom-filter ref="clientCredentialsTokenEndpointFilter"
before="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http pattern="/api/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/api/**" access="IS_AUTHENTICATED_FULLY" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http pattern="/logout" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/logout" method="GET" />
<sec:logout invalidate-session="true" logout-url="/logout"
success-handler-ref="logoutSuccessHandler" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<bean id="logoutSuccessHandler" class="com.monsor.feasthub.security.LogoutImpl">
<property name="tokenstore" ref="tokenStore" />
</bean>
<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint" />
<bean id="applicationContextProvder" class="com.monsor.feasthub.util.ApplicationContextProvider" />
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="springsec/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<bean id="clientDetailsUserService" class="com.monsor.feasthub.security.CustomUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<bean id="clientDetails" class="com.monsor.feasthub.security.ClientDetailsServiceImpl" />
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password authentication-manager-ref="userAuthenticationManager" />
</oauth:authorization-server>
<authentication-manager id="userAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider ref="customUserAuthenticationProvider" />
</authentication-manager>
<bean id="customUserAuthenticationProvider"
class="com.monsor.feasthub.security.CustomUserAuthenticationProvider" />
<oauth:resource-server id="resourceServerFilter"
resource-id="springsec" token-services-ref="tokenServices" />
<bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore" />
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="accessTokenValiditySeconds" value="300000" />
<property name="clientDetailsService" ref="clientDetails" />
</bean>
<mvc:annotation-driven /> <!-- Declares explicit support for annotation-driven MVC controllers #RequestMapping,
#Controller -->
<mvc:default-servlet-handler />
<bean id="MyResource" class="com.monsor.feasthub.resources.MyResource" />
</beans>

SharePoint Online BCS OData External Content Can't Update, View or Delete

Using Visual Studio 2013, I created an Entity Model over an existing database. Each table has a GUID for it's primary key. I created an MVC Web API project with related OData Bindings and Controllers.
Here is how I create the OData Binding;
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<HRPosition>("HRPositions").EntityType.HasKey(p=>p.HTPositionGuid);
Here is a sample controller for the HRPositions Entity.
public class HRPositionsController : ODataController
{
private EFSEntities db = new EFSEntities();
// GET: odata/HRPositions
[EnableQuery]
public IQueryable<HRPosition> GetHRPositions()
{
return db.HRPositions;
}
// GET: odata/HRPositions(5)
[EnableQuery]
public SingleResult<HRPosition> GetHRPosition([FromODataUri] Guid key)
{
return SingleResult.Create(db.HRPositions.Where(hRPosition => hRPosition.HTPositionGuid == key));
}
// PUT: odata/HRPositions(5)
public async Task<IHttpActionResult> Put([FromODataUri] Guid key, Delta<HRPosition> patch)
{
Validate(patch.GetEntity());
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
HRPosition hRPosition = await db.HRPositions.FindAsync(key);
if (hRPosition == null)
{
return NotFound();
}
patch.Put(hRPosition);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!HRPositionExists(key))
{
return NotFound();
}
else
{
throw;
}
}
return Updated(hRPosition);
}
// POST: odata/HRPositions
public async Task<IHttpActionResult> Post(HRPosition hRPosition)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.HRPositions.Add(hRPosition);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (HRPositionExists(hRPosition.HTPositionGuid))
{
return Conflict();
}
else
{
throw;
}
}
return Created(hRPosition);
}
// PATCH: odata/HRPositions(5)
[AcceptVerbs("PATCH", "MERGE")]
public async Task<IHttpActionResult> Patch([FromODataUri] Guid key, Delta<HRPosition> patch)
{
Validate(patch.GetEntity());
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
HRPosition hRPosition = await db.HRPositions.FindAsync(key);
if (hRPosition == null)
{
return NotFound();
}
patch.Patch(hRPosition);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!HRPositionExists(key))
{
return NotFound();
}
else
{
throw;
}
}
return Updated(hRPosition);
}
// DELETE: odata/HRPositions(5)
public async Task<IHttpActionResult> Delete([FromODataUri] Guid key)
{
HRPosition hRPosition = await db.HRPositions.FindAsync(key);
if (hRPosition == null)
{
return NotFound();
}
db.HRPositions.Remove(hRPosition);
await db.SaveChangesAsync();
return StatusCode(HttpStatusCode.NoContent);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
private bool HRPositionExists(Guid key)
{
return db.HRPositions.Count(e => e.HTPositionGuid == key) > 0;
}
}
Once the OData Service is deployed and using Fiddler I am able to query the Service endpoints and retrieve the full list of data as well as single entity data.
I then created a SharePoint App in which I create an External Content Type by referencing the OData service. This creates the ECT Model definitions for each endpoint.
Here is the ECT for HRPositions;
<?xml version="1.0" encoding="utf-16"?>
<Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="EFSData" xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog">
<LobSystems>
<LobSystem Name="EFSODATA" Type="OData">
<Properties>
<Property Name="ODataServiceMetadataUrl" Type="System.String">https://efsodataapi.azurewebsites.net/OData/$metadata</Property>
<Property Name="ODataServiceMetadataAuthenticationMode" Type="System.String">PassThrough</Property>
<Property Name="ODataServicesVersion" Type="System.String">2.0</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<LobSystemInstances>
<LobSystemInstance Name="EFSODATA">
<Properties>
<Property Name="ODataServiceUrl" Type="System.String">https://efsodataapi.azurewebsites.net/OData</Property>
<Property Name="ODataServiceAuthenticationMode" Type="System.String">PassThrough</Property>
<Property Name="ODataFormat" Type="System.String">application/atom+xml</Property>
<Property Name="HttpHeaderSetAcceptLanguage" Type="System.Boolean">true</Property>
</Properties>
</LobSystemInstance>
</LobSystemInstances>
<Entities>
<Entity Name="HRPositions" DefaultDisplayName="HRPositions" Namespace="EFSData" Version="1.0.0.0" EstimatedInstanceCount="2000">
<Properties>
<Property Name="ExcludeFromOfflineClientForList" Type="System.String">False</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<Identifiers>
<Identifier Name="HTPositionGuid" TypeName="System.Guid" />
</Identifiers>
<Methods>
<Method Name="CreateHRPosition" DefaultDisplayName="Create HRPosition" IsStatic="false">
<Properties>
<Property Name="ODataEntityUrl" Type="System.String">/HRPositions</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<Parameters>
<Parameter Name="#HTPositionGuid" Direction="In">
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" CreatorField="true" />
</Parameter>
<Parameter Name="#PosistionCode" Direction="In">
<TypeDescriptor Name="PosistionCode" DefaultDisplayName="PosistionCode" TypeName="System.String" CreatorField="true" />
</Parameter>
<Parameter Name="#PositionName" Direction="In">
<TypeDescriptor Name="PositionName" DefaultDisplayName="PositionName" TypeName="System.String" CreatorField="true" />
</Parameter>
<Parameter Name="#Description" Direction="In">
<TypeDescriptor Name="Description" DefaultDisplayName="Description" TypeName="System.String" CreatorField="true" />
</Parameter>
<Parameter Name="#CreateHRPosition" Direction="Return">
<TypeDescriptor Name="CreateHRPosition" DefaultDisplayName="CreateHRPosition" TypeName="Microsoft.BusinessData.Runtime.DynamicType">
<TypeDescriptors>
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" ReadOnly="true" />
<TypeDescriptor Name="PosistionCode" DefaultDisplayName="PosistionCode" TypeName="System.String" />
<TypeDescriptor Name="PositionName" DefaultDisplayName="PositionName" TypeName="System.String" />
<TypeDescriptor Name="Description" DefaultDisplayName="Description" TypeName="System.String" />
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="CreateHRPosition" Type="Creator" ReturnParameterName="#CreateHRPosition" ReturnTypeDescriptorPath="CreateHRPosition">
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
</MethodInstance>
</MethodInstances>
</Method>
<Method Name="ReadSpecificHRPosition" DefaultDisplayName="Read Specific HRPosition" IsStatic="false">
<Properties>
<Property Name="ODataEntityUrl" Type="System.String">/HRPositions(HTPositionGuid=guid'#HTPositionGuid')</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<Parameters>
<Parameter Name="#HTPositionGuid" Direction="In">
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" />
</Parameter>
<Parameter Name="#HRPosition" Direction="Return">
<TypeDescriptor Name="HRPosition" DefaultDisplayName="HRPosition" TypeName="Microsoft.BusinessData.Runtime.DynamicType">
<TypeDescriptors>
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" ReadOnly="true" />
<TypeDescriptor Name="PosistionCode" DefaultDisplayName="PosistionCode" TypeName="System.String" />
<TypeDescriptor Name="PositionName" DefaultDisplayName="PositionName" TypeName="System.String" />
<TypeDescriptor Name="Description" DefaultDisplayName="Description" TypeName="System.String" />
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="ReadSpecificHRPosition" Type="SpecificFinder" Default="true" ReturnParameterName="#HRPosition" ReturnTypeDescriptorPath="HRPosition">
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
</MethodInstance>
</MethodInstances>
</Method>
<Method Name="ReadAllHRPosition" DefaultDisplayName="Read All HRPosition" IsStatic="false">
<Properties>
<Property Name="ODataEntityUrl" Type="System.String">/HRPositions?$top=#LimitHRPositionss</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<FilterDescriptors>
<FilterDescriptor Name="LimitFilter" DefaultDisplayName="LimitFilter" Type="Limit" />
</FilterDescriptors>
<Parameters>
<Parameter Name="#LimitHRPositionss" Direction="In">
<TypeDescriptor Name="LimitHRPositionss" DefaultDisplayName="LimitHRPositionss" TypeName="System.Int32" AssociatedFilter="LimitFilter">
<Properties>
<Property Name="LogicalOperatorWithPrevious" Type="System.String">None</Property>
<Property Name="Order" Type="System.String">0</Property>
</Properties>
<DefaultValues>
<DefaultValue MethodInstanceName="ReadAllHRPosition" Type="System.Int32">100</DefaultValue>
</DefaultValues>
</TypeDescriptor>
</Parameter>
<Parameter Name="#HRPositions" Direction="Return">
<TypeDescriptor Name="HRPositions" DefaultDisplayName="HRPositions" TypeName="Microsoft.BusinessData.Runtime.IDynamicTypeEnumerator" IsCollection="true">
<TypeDescriptors>
<TypeDescriptor Name="HRPosition" DefaultDisplayName="HRPosition" TypeName="Microsoft.BusinessData.Runtime.DynamicType">
<TypeDescriptors>
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" ReadOnly="true" />
<TypeDescriptor Name="PosistionCode" DefaultDisplayName="PosistionCode" TypeName="System.String" />
<TypeDescriptor Name="PositionName" DefaultDisplayName="PositionName" TypeName="System.String" />
<TypeDescriptor Name="Description" DefaultDisplayName="Description" TypeName="System.String" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="ReadAllHRPosition" Type="Finder" Default="true" ReturnParameterName="#HRPositions" ReturnTypeDescriptorPath="HRPositions">
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
</MethodInstance>
</MethodInstances>
</Method>
<Method Name="UpdateHRPosition" DefaultDisplayName="Update HRPosition" IsStatic="false">
<Properties>
<Property Name="ODataEntityUrl" Type="System.String">/HRPositions(HTPositionGuid=guid'#HTPositionGuid')</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<Parameters>
<Parameter Name="#HTPositionGuid" Direction="In">
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" UpdaterField="true" />
</Parameter>
<Parameter Name="#PosistionCode" Direction="In">
<TypeDescriptor Name="PosistionCode" DefaultDisplayName="PosistionCode" TypeName="System.String" UpdaterField="true" />
</Parameter>
<Parameter Name="#PositionName" Direction="In">
<TypeDescriptor Name="PositionName" DefaultDisplayName="PositionName" TypeName="System.String" UpdaterField="true" />
</Parameter>
<Parameter Name="#Description" Direction="In">
<TypeDescriptor Name="Description" DefaultDisplayName="Description" TypeName="System.String" UpdaterField="true" />
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="UpdateHRPosition" Type="Updater">
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
</MethodInstance>
</MethodInstances>
</Method>
<Method Name="DeleteHRPosition" DefaultDisplayName="Delete HRPosition" IsStatic="false">
<Properties>
<Property Name="ODataEntityUrl" Type="System.String">/HRPositions(HTPositionGuid=guid'#HTPositionGuid')</Property>
</Properties>
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
<Parameters>
<Parameter Name="#HTPositionGuid" Direction="In">
<TypeDescriptor Name="HTPositionGuid" DefaultDisplayName="HTPositionGuid" TypeName="System.Guid" IdentifierName="HTPositionGuid" />
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="DeleteHRPosition" Type="Deleter">
<AccessControlList>
<AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string">
<Right BdcRight="Edit" />
<Right BdcRight="Execute" />
<Right BdcRight="SelectableInClients" />
<Right BdcRight="SetPermissions" />
</AccessControlEntry>
</AccessControlList>
</MethodInstance>
</MethodInstances>
</Method>
</Methods>
</Entity>
</Entities>
</LobSystem>
</LobSystems>
</Model>
I uploaded the ECT into SharePoint Online BCS and all looks fine;
From there I create an external list and reference the HRPositions ECT, which creates and SP List but is missing the primary key (which is the GUID).
This view shows the proper data;
I am able to add a new item to the list;
And it shows in the read all view;
But I can't edit, delete or view any list item as I get this error for each operation;
I attached to the OData Web Service and could see why the issue is occurring. Turns out the Auto-Generated External Control Types (ECT) within Visual Studio that were reflected off the OData Service have an issue in that for some reason it is formulating the request as /HRPositions(HTPositionGuid=guid'#HTPositionGuid');
It should really only be /HRPositions(guid'#HTPositionGuid');
Can anyone tell me why it's including the HTPositionGuid= within the Parameter list?
I can manually edit the code-generated ECT files for each entity but that seems silly.

Tiles attributes not found

I use tiles 2.0
In my tiles-defs.xml i have
<definition name="user" extends="baseLayout">
<put-attribute name="title" value="Share Admin user" />
<put-attribute name="body" value="user.body" />
</definition>
<definition name="user.body" template="/WEB-INF/view/user.jsp">
<put-attribute name="editingUserForm" value="/WEB-INF/view/userEditingModelFormModal.jsp"/>
</definition>
in my user.jsp i have
<tiles:insertAttribute name="editingUserForm" />
when i load my user page, i get
org.apache.tiles.template.NoSuchAttributeException: Attribute 'editingUserForm' not found.
/WEB-INF/tiles/tiles-defs.xml
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="order" value="1" />
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
#RequestMapping(method = RequestMethod.GET, value = "/admin/editingUser")
public String showAjaxEditingUser(Model model, #RequestParam("username") String userName) {
UserBean userBean = userBeanMap.get(userName);
model.addAttribute("editingUser", userBean);
return "editingUserFormBodyPart";
}

How do I get an attribute using the 'amazon-ecs' gem?

I am using Amazon Product Advertising API (amazon-ecs) gem, but I am using the item_lookup method instead of item_search, which is the only one documented.
I am looking to return the item TradeInValue but I am confused as to how to do that. It is clearly being returned, but I am not sure how to parse it.
This is the call:
Amazon::Ecs.item_lookup('9780521153348', :response_group => 'ItemAttributes', :id_type => 'ISBN', :search_index => 'Books')
And this is the return, which I am not sure what to do with. The methods in amazon-ecs don't seem to work for item_lookup and XPath isn't working either:
#<Amazon::Ecs::Response:0x007ff3325250d0 #doc=#<Nokogiri::XML::Document:0x3ff9992927a0 name="document" children=[#<Nokogiri::XML::Element:0x3ff997067414 name="ItemLookupResponse" children=[#<Nokogiri::XML::Element:0x3ff99706b924 name="OperationRequest" children=[#<Nokogiri::XML::Element:0x3ff99706b474 name="HTTPHeaders" children=[#<Nokogiri::XML::Element:0x3ff99706f470 name="Header" attributes=[#<Nokogiri::XML::Attr:0x3ff99706f0ec name="Name" value="UserAgent">, #<Nokogiri::XML::Attr:0x3ff99706f074 name="Value" value="Ruby">]>]>, #<Nokogiri::XML::Element:0x3ff9970760cc name="RequestId" children=[#<Nokogiri::XML::Text:0x3ff999296468 "053626d3-e3cd-47d2-bc8b-7ac6a0c5f6d2">]>, #<Nokogiri::XML::Element:0x3ff99929f6f8 name="Arguments" children=[#<Nokogiri::XML::Element:0x3ff9992a3bb8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992a3960 name="Name" value="Operation">, #<Nokogiri::XML::Attr:0x3ff9992a3938 name="Value" value="ItemLookup">]>, #<Nokogiri::XML::Element:0x3ff9992a73f8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992a7204 name="Name" value="Signature">, #<Nokogiri::XML::Attr:0x3ff9992a7010 name="Value" value="IMd3D0DGgAcaLR6XcuObzdAgFbOya7mbIRtZFbNijVA=">]>, #<Nokogiri::XML::Element:0x3ff9992ab41c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992ab2dc name="Name" value="AssociateTag">, #<Nokogiri::XML::Attr:0x3ff9992ab2c8 name="Value" value="textscom-20">]>, #<Nokogiri::XML::Element:0x3ff9992af774 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992af6ac name="Name" value="ItemId">, #<Nokogiri::XML::Attr:0x3ff9992af698 name="Value" value="9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9992b0c3c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b0b4c name="Name" value="IdType">, #<Nokogiri::XML::Attr:0x3ff9992b0b10 name="Value" value="ISBN">]>, #<Nokogiri::XML::Element:0x3ff9992b7794 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b7578 name="Name" value="AWSAccessKeyId">, #<Nokogiri::XML::Attr:0x3ff9992b7550 name="Value" value="AKIAJLOCEGWTFXZKXLEQ">]>, #<Nokogiri::XML::Element:0x3ff9992b2244 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b208c name="Name" value="Timestamp">, #<Nokogiri::XML::Attr:0x3ff9992b2064 name="Value" value="2013-05-07T17:46:35Z">]>, #<Nokogiri::XML::Element:0x3ff9992bffc0 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992bff20 name="Name" value="ResponseGroup">, #<Nokogiri::XML::Attr:0x3ff9992bff0c name="Value" value="ItemAttributes">]>, #<Nokogiri::XML::Element:0x3ff9992be1e8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992c38c8 name="Name" value="SearchIndex">, #<Nokogiri::XML::Attr:0x3ff9992c3a30 name="Value" value="Books">]>, #<Nokogiri::XML::Element:0x3ff9992ca95c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992ca344 name="Name" value="Service">, #<Nokogiri::XML::Attr:0x3ff9992ca2a4 name="Value" value="AWSECommerceService">]>]>, #<Nokogiri::XML::Element:0x3ff9992d3d7c name="RequestProcessingTime" children=[#<Nokogiri::XML::Text:0x3ff9992d382c "0.0289960000000000">]>]>, #<Nokogiri::XML::Element:0x3ff9992d7eb8 name="Items" children=[#<Nokogiri::XML::Element:0x3ff9992d7148 name="Request" children=[#<Nokogiri::XML::Element:0x3ff9992d6900 name="IsValid" children=[#<Nokogiri::XML::Text:0x3ff9992dae10 "True">]>, #<Nokogiri::XML::Element:0x3ff9992da758 name="ItemLookupRequest" children=[#<Nokogiri::XML::Element:0x3ff9992df884 name="IdType" children=[#<Nokogiri::XML::Text:0x3ff9992df014 "ISBN">]>, #<Nokogiri::XML::Element:0x3ff9992de678 name="ItemId" children=[#<Nokogiri::XML::Text:0x3ff9992e2e1c "9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9983a5580 name="ResponseGroup" children=[#<Nokogiri::XML::Text:0x3ff9983a59b8 "ItemAttributes">]>, #<Nokogiri::XML::Element:0x3ff9983a510c name="SearchIndex" children=[#<Nokogiri::XML::Text:0x3ff9983a43c4 "Books">]>, #<Nokogiri::XML::Element:0x3ff9983a925c name="VariationPage" children=[#<Nokogiri::XML::Text:0x3ff9983a8d0c "All">]>]>]>, #<Nokogiri::XML::Element:0x3ff9983a8244 name="Item" children=[#<Nokogiri::XML::Element:0x3ff9983add70 name="ASIN" children=[#<Nokogiri::XML::Text:0x3ff9983ad6f4 "0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983acc04 name="DetailPageURL" children=[#<Nokogiri::XML::Text:0x3ff9983ac4d4 "http://www.amazon.com/Turgot-Progress-Sociology-Economics-Philosophical/dp/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983b1768 name="ItemLinks" children=[#<Nokogiri::XML::Element:0x3ff9983b1024 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b0a20 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b028c "Technical Details">]>, #<Nokogiri::XML::Element:0x3ff9983b5b60 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b5638 "http://www.amazon.com/Turgot-Progress-Sociology-Economics-Philosophical/dp/tech-data/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983b5034 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b4a58 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b46d4 "Add To Baby Registry">]>, #<Nokogiri::XML::Element:0x3ff9983b406c name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b9ad0 "http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983b95d0 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b9080 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b8cd4 "Add To Wedding Registry">]>, #<Nokogiri::XML::Element:0x3ff9983b8a2c name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b834c "http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983bcff0 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983bc49c name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983bc0f0 "Add To Wishlist">]>, #<Nokogiri::XML::Element:0x3ff9983c1b40 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983c158c "http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983c01dc name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983c5da8 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983c595c "Tell A Friend">]>, #<Nokogiri::XML::Element:0x3ff9983c5358 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983c4674 "http://www.amazon.com/gp/pdp/taf/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983c9750 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983c8828 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983cc888 "All Customer Reviews">]>, #<Nokogiri::XML::Element:0x3ff9983d1f18 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983d19c8 "http://www.amazon.com/review/product/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983d152c name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983d107c name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983d02d0 "All Offers">]>, #<Nokogiri::XML::Element:0x3ff9983d5730 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983d4e48 "http://www.amazon.com/gp/offer-listing/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>]>, #<Nokogiri::XML::Element:0x3ff9983dd00c name="ItemAttributes" children=[#<Nokogiri::XML::Element:0x3ff9983dc33c name="Author" children=[#<Nokogiri::XML::Text:0x3ff9983e1364 "Ronald L. Meek">]>, #<Nokogiri::XML::Element:0x3ff9983e0af4 name="Binding" children=[#<Nokogiri::XML::Text:0x3ff9983e04a0 "Paperback">]>, #<Nokogiri::XML::Element:0x3ff9983e0068 name="EAN" children=[#<Nokogiri::XML::Text:0x3ff9983e5c34 "9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9983e5270 name="EANList" children=[#<Nokogiri::XML::Element:0x3ff9983e4424 name="EANListElement" children=[#<Nokogiri::XML::Text:0x3ff9983d7c60 "9780521153348">]>]>, #<Nokogiri::XML::Element:0x3ff9983d7724 name="ISBN" children=[#<Nokogiri::XML::Text:0x3ff9983d7120 "0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983d6cc0 name="IsEligibleForTradeIn" children=[#<Nokogiri::XML::Text:0x3ff9983d6130 "1">]>, #<Nokogiri::XML::Element:0x3ff9983d99c0 name="ItemDimensions" children=[#<Nokogiri::XML::Element:0x3ff9983d963c name="Height" attributes=[#<Nokogiri::XML::Attr:0x3ff9983d959c name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983d83cc "902">]>, #<Nokogiri::XML::Element:0x3ff9983ed7a4 name="Length" attributes=[#<Nokogiri::XML::Attr:0x3ff9983ed448 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983f3244 "598">]>, #<Nokogiri::XML::Element:0x3ff9983f290c name="Weight" attributes=[#<Nokogiri::XML::Attr:0x3ff9983f26f0 name="Units" value="hundredths-pounds">] children=[#<Nokogiri::XML::Text:0x3ff9983e93c0 "64">]>, #<Nokogiri::XML::Element:0x3ff9983e8f38 name="Width" attributes=[#<Nokogiri::XML::Attr:0x3ff9983e8e34 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983efa2c "43">]>]>, #<Nokogiri::XML::Element:0x3ff9983ef144 name="Label" children=[#<Nokogiri::XML::Text:0x3ff9983eecbc "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9983ee988 name="Languages" children=[#<Nokogiri::XML::Element:0x3ff9983ee410 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a80009c name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a801a14 "English">]>, #<Nokogiri::XML::Element:0x3ff99a8010f0 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a800948 "Unknown">]>]>, #<Nokogiri::XML::Element:0x3ff99a800574 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a8002b8 name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a80419c "English">]>, #<Nokogiri::XML::Element:0x3ff99a805484 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a804b10 "Original Language">]>]>, #<Nokogiri::XML::Element:0x3ff99a804070 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a808d64 name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a80d6d4 "English">]>, #<Nokogiri::XML::Element:0x3ff99a80c680 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a8110a4 "Published">]>]>]>, #<Nokogiri::XML::Element:0x3ff99a8157a8 name="ListPrice" children=[#<Nokogiri::XML::Element:0x3ff99a8142cc name="Amount" children=[#<Nokogiri::XML::Text:0x3ff99a819358 "2899">]>, #<Nokogiri::XML::Element:0x3ff99a818d04 name="CurrencyCode" children=[#<Nokogiri::XML::Text:0x3ff99a818764 "USD">]>, #<Nokogiri::XML::Element:0x3ff99a81c8a0 name="FormattedPrice" children=[#<Nokogiri::XML::Text:0x3ff99a81d534 "$28.99">]>]>, #<Nokogiri::XML::Element:0x3ff99a81ccb0 name="Manufacturer" children=[#<Nokogiri::XML::Text:0x3ff99a81c648 "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff99a81c2d8 name="NumberOfItems" children=[#<Nokogiri::XML::Text:0x3ff99a821cec "1">]>, #<Nokogiri::XML::Element:0x3ff99a821580 name="NumberOfPages" children=[#<Nokogiri::XML::Text:0x3ff99a82043c "194">]>, #<Nokogiri::XML::Element:0x3ff99a825bbc name="PackageDimensions" children=[#<Nokogiri::XML::Element:0x3ff99a824cd0 name="Height" attributes=[#<Nokogiri::XML::Attr:0x3ff99a824b68 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff99a824168 "63">]>, #<Nokogiri::XML::Element:0x3ff99a829d98 name="Length" attributes=[#<Nokogiri::XML::Attr:0x3ff99a829d20 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff99a828eac "890">]>, #<Nokogiri::XML::Element:0x3ff99a828c68 name="Weight" attributes=[#<Nokogiri::XML::Attr:0x3ff99a828b8c name="Units" value="hundredths-pounds">] children=[#<Nokogiri::XML::Text:0x3ff99a828074 "66">]>, #<Nokogiri::XML::Element:0x3ff9983f69d0 name="Width" attributes=[#<Nokogiri::XML::Attr:0x3ff9983f68f4 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff997c6340c "598">]>]>, #<Nokogiri::XML::Element:0x3ff997c62cf0 name="ProductGroup" children=[#<Nokogiri::XML::Text:0x3ff997c623b8 "Book">]>, #<Nokogiri::XML::Element:0x3ff9961e1d2c name="ProductTypeName" children=[#<Nokogiri::XML::Text:0x3ff9961e0e40 "ABIS_BOOK">]>, #<Nokogiri::XML::Element:0x3ff9961e0508 name="PublicationDate" children=[#<Nokogiri::XML::Text:0x3ff9961e7b28 "2010-06-10">]>, #<Nokogiri::XML::Element:0x3ff9961e75c4 name="Publisher" children=[#<Nokogiri::XML::Text:0x3ff9961e727c "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9961e70b0 name="SKU" children=[#<Nokogiri::XML::Text:0x3ff9961e6bc4 "Y9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9961e682c name="Studio" children=[#<Nokogiri::XML::Text:0x3ff9961ebc64 "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9961ea120 name="Title" children=[#<Nokogiri::XML::Text:0x3ff996f67ac8 "Turgot on Progress, Sociology and Economics: A Philosophical Review of the Successive Advances of the Human Mind on Universal History Reflections on ... in the History and Theory of Politics)">]>, #<Nokogiri::XML::Element:0x3ff996f676cc name="TradeInValue" children=[#<Nokogiri::XML::Element:0x3ff996f67028 name="Amount" children=[#<Nokogiri::XML::Text:0x3ff996f66ca4 "310">]>, #<Nokogiri::XML::Element:0x3ff996f669d4 name="CurrencyCode" children=[#<Nokogiri::XML::Text:0x3ff996f663a8 "USD">]>, #<Nokogiri::XML::Element:0x3ff996fadbb8 name="FormattedPrice" children=[#<Nokogiri::XML::Text:0x3ff996fad014 "$3.10">]>]>]>]>]>]>]>>
Okay, I figured it out. I was trying to treat item_lookup as a single return value, rather than a hash the way search is returned.
item_lookup is basically the same as item_search:
res = Amazon::Ecs.item_lookup('9780521153348', :response_group => 'ItemAttributes', :id_type => 'ISBN', :search_index => 'Books')
res.items.each do |item|
puts item.get('ItemAttributes/TradeInValue/FormattedPrice')
end

"An item with the same key has already been added" error when calling Context AddObject

Can somebody please help me with this error. I have an ASP.NET WebApp, within the Entity Model I have an entity called tb_AdminUser, with a UserID property as GUID. This is also the Entity Key. The entity is not in any relationship with any other entity. I get the error when calling the AddObject() function.
In my code I call the following...
SQL2008R2_824852_leapdbEntities temp = new SQL2008R2_824852_leapdbEntities();
tb_AdminUser au = new tb_AdminUser();
au.UserID = Guid.NewGuid();
au.Username = "TEST";
au.Password = "pete#webinspired.net";
au.LockedOut = false;
au.Surname = "Feehan";
au.Forename = "Pete";
temp.tb_AdminUser.AddObject(au); //error occurs here
temp.SaveChanges();
The EDMX XML Code is as follows
<EntityType Name="tb_AdminUser">
<Key>
<PropertyRef Name="UserID" />
</Key>
<Property Name="UserID" Type="uniqueidentifier" Nullable="false" />
<Property Name="Forename" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Surname" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Username" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Password" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="LockedOut" Type="bit" Nullable="false" />
</EntityType>

Resources