What I have done in the past is capture each return in the mapping. So in your SPROC, comment out all but one of the selects. Then map the SPROC. You will then end up with an entity object. Copy the code for that object to another file. Rinse and repeat for all of the objects.
Then you can specify which object. So if I have a SPROC GetEmployee but it also gets all of the Projects that the employee works on I can say
var projects = GetResult<Projects>();
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
Using VB targeting V4.0 of the .net framework, I'm trying to filter an in-memory datatable using linq and want the results in a datatable.
For example, the following linq query works:
dim query=(from customers in dtcustomers.asenumerable
where customers.state = "VA"select customers).copytodatatable
This works as long as the query returns at least 1 match from the table. If no match is found, I end up with an unhandled InvalidOperationException because the source contains no datarows.
Every example I can find of copytodatatable usage is in this form:
dim query=from customers in dtcustomers.asenumerable
where customers.state = "VA"
dim dtNewTable as datatable=query.copytodatatable
My thought was to use something similar to the second example and test for a result from the query prior to calling copytodatatable, but anytime I try to use copytodatatable outside the query itself, I get : "Public member 'copytodatatable' on type 'EnumerableRowCollection(Of CustomerRow)' not found."
I've seen plenty of similar posts about MissingMemberExceptions when using copytodatatable but it's usually due to a missing reference. I've added the reference and 'copytodatatable' works but only if it's in the query itself.
in my app framework we have different .NET services on either the same or different physical machines. The current .NET Remoting may or may not be switched to WCF one day. Regardless of that I did not find a statement on the web if it is possible to serialize a Linq request and get the reply back over the wire. Currently we are using handcrafted abstraction objects for the query part and return DataTables, Scalars etc...
Out of the box EF4 entity objects do not support serialization. You need to convert your model to POCO objects using the ‘ADO.NET POCO Entity Generator’ or the ‘ADO.NET DbContext Generator’(depending on your EF4 version).
This can be done automatically by right-clicking on the model design surface and selecting ‘Add Code Generated Item’. From the dialog, select ‘Online Templates’ and the desired generator. Type a name for your T4 template (your model name).
A simple POCO class will be created for each entity.
To send and receive the POCO classes over the wire via WCF you will need to add some class files/ class project (CyclicReferencesAware and DataContractResolver) and some supporting attributes to the code generated web services interface classes.
Here are some links (walk troughs) that explain the process.
I need to sum field depending on 2 tables with 1 to many relations
I have somewhere in my project the following
Dim lqcus = From c In db0.customers Where c.id = txt_idcust.Text Select c
I managed to sum by 2 ways
Dim sum1 = (From s In db0.stocks Where s.CustID = txt_idcust.Text Select c.qty).Sum
Dim sum2 = Aggregate s In db0.stocks Where s.CustID = txt_idcust.Text Into sum(s.qty)
But the above 2 will be executed again in the sql server to get the result, but I already have the lqcus which is linq result for the customer and inside the lqcus there is the stock already filtered by the 1 to many relation
For example, I can write the following
Dim sum3 = From s In lqcus.stocks Where s.CustID = txt_idcust.Text
But I could not find the syntax to sum the qty
Can someone help?
modified on Tuesday, July 19, 2011 6:36 AM
Last Visit: 31-Dec-99 18:00 Last Update: 8-Mar-14 8:44