The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Congero (2) [Avatar] Offline
#1
I am attempting to use linq to retreive data from an existing web service where I retreive a data table with an underscore and period in the data table name. ( I cannot change the name of the data table)

Here is my code snippet
Dim dt as datatable = dsCustomer.Tables(0)
<%= From c In dt.AsEnumerable() _ <br /> Select <Customer>
<FullName><%= c!VwCustomerLookup_.FullName %></FullName>
<LastName><%= c!VwCustomerLookup_.LastName %></LastName>
</Customer> _
%>
</CustomerInfo>


The webservice compiles but when I execute it throws the following exception
System.ArgumentException: Column 'VwCustomerLookup_' does not belong to table vwCustomerLookup.
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
at WebService1._Lambda$__1(DataRow c) in D:App_CodeWebService1.asmx.vb:line 63
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Xml.Linq.XContainer.AddContentSkipNotify(Object content)
at System.Xml.Linq.XElement..ctor(XName name, Object content)
at WebService1.AATestLookup(String Criteria) in D:App_CodeWebService1.asmx.vb:line 60

Any help would be appreciated
(I already tried to truncate the field name to "Fullname" and it throws a similar error)
Thanks
jwooley (123) [Avatar] Offline
#2
Re: Linq to Dataset / vb xml Literals Issue
In your projection, it appears that you are not using the data that's your source. Assuming dsCustomer.Tables(0) is the same as clVwCustomerLookup_. then you should just be able to use c to represent the table. It would seem the following should work for you:

Dim dt as datatable = dsCustomer.Tables(0)
Dim CustInfo = <CustomerInfo>
<%= From c In dt _ <br /> Select <Customer>
<FullName><%= c.FullName %></FullName>
<LastName><%= c.LastName %></LastName>
</Customer> _
%>
</CustomerInfo>

Note, in VB the .AsEnumerable is assumed so you don't need it there.
Congero (2) [Avatar] Offline
#3
Re: Linq to Dataset / vb xml Literals Issue
First, thank you for you interest and suggestion.

I agree, I thought c!FullName should work but the column name is literally "vwCustomerLookup_.Fullname" and I have to use the bang operator(!)

for example if I use

<FullName><%= c!FullName %></FullName>
<LastName><%= c!LastName %></LastName>

it will still throw the exception
System.ArgumentException: Column 'FullName' does not belong to table vwCustomerLookup.
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName).....
and so on

It appears that a column name with a period (.) in it is not acceptable. Is there any way I can alias the column name?
jwooley (123) [Avatar] Offline
#4
Re: Linq to Dataset / vb xml Literals Issue
Ok, I thought you had a strongly typed dataset. Have you tried using the untyped dataset syntax: vwCustomerLookup.Fields("_Fullname")? I suspect you can't use the bang, but that's a VB only shortcut for the list index accessor anyway.

Jim