?
Solved

Sequence and number of calls matters?

Posted on 2013-07-01
5
Medium Priority
?
316 Views
Last Modified: 2013-07-03
 CompositeKey ck = new CompositeKey(UserIDSID);

                UserProfileDataContext udc = new UserProfileDataContext();
                var results = udc.Users_get(ck.PrimaryID, ck.ServerID, CurrentUser.UserID, CurrentUser.UserSID);

                UserProfileDataContext udc2 = new UserProfileDataContext();             

                User = results.GetResult<Users_Get>().FirstOrDefault();
                ServiceList = results.GetResult<Users_Services>().ToList();
                CapacityList = results.GetResult<UserRole_DisplayResult>().ToList();
                AgentData = results.GetResult<AgentInfo>().FirstOrDefault();
                RolesList = results.GetResult<int>().ToList();
                AgentLicense = results.GetResult<License>().ToList();
                BrokerLicense = results.GetResult<License>().ToList();
                Insurance = results.GetResult<Insurance_GetResult>().ToList();
                MLSInfoList = results.GetResult<MLSInfo_GetResult>().ToList();
                ProfileList = results.GetResult<User_ProfileValidation_UpdateResult>().ToList();
                merchantStates = results.GetResult<MerchantStates>().ToList();

Open in new window


Consider this line towards the bottom of the code snippet:

merchantStates = results.GetResult<MerchantStates>().ToList();

merchantStates will have the correct number of entries.


However, if I run the following code, merchantSites does not have the correct data:

 CompositeKey ck = new CompositeKey(UserIDSID);

                UserProfileDataContext udc = new UserProfileDataContext();
                var results = udc.Users_get(ck.PrimaryID, ck.ServerID, CurrentUser.UserID, CurrentUser.UserSID);

                UserProfileDataContext udc2 = new UserProfileDataContext();             

                User = results.GetResult<Users_Get>().FirstOrDefault();
                merchantStates = results.GetResult<MerchantStates>().ToList();

Open in new window



The difference is that the calls that were made in the code above were removed.



Why are the other calls necessary for this code to correctly fill merchantStates?

It almost seems like each call is moving the "cursor" to the next set of data.

Is there a way to make it so it will find and use the CORRECT method (by name) instead of seemingly finding the correct method by how many calls have been made against the results var?
0
Comment
Question by:Tom Knowlton
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:jonnidip
ID: 39292164
What does the "GetResult" method do?
And what is the data type returned by "Users_get"?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 39293763
What does the "GetResult" method do?
And what is the data type returned by "Users_get"?

Wait a minute...aren't you supposed to be answering questions, not asking them?  : P

(I am totally kidding)

Well, the data type returned is IMultipleResult.  So I get that multiple "result sets" can be returned by the result var.

I just don't understand why I have to call 8 or 9  "Get Results" methods in order to get to the one where the "merchantStates" List<  >  gets filled.

I only care about filling Users and merchantStates.  The other calls are wasted, except for the fact that they seem to advance the result set "cursor" so that it will return the correct results.

GetResult(  )  returns an IEnumerable.
0
 
LVL 13

Accepted Solution

by:
jonnidip earned 2000 total points
ID: 39295581
Hi, by using the IMultipleResult interface the only way to get all single results (or one specific result) is to get any previous result too.
This is because in your query or stored procedure you return multiple resultsets (say, multiple queries). The IMultipleResults can keep these results, but you have to get them all if you need the last one...
The order of the resultsets is the same of your queries, so you need to keep this in mind.

If you really don't need the other objects, you may consider rewriting your procedure.
In my experience I avoid returning multiple results in a single query, I'd rather prefer to call multiple queries in distinct methods/objects.

You may take a look at my article about creating entity classes from a db query.
That is my approach for client/server applications where bandwidth is limited (you will see that I serialize and compress the classes), but the class/entity creation is how I intend the things.

In your case I would create a structured object (a class with fields of type ServiceList, CapacityList...) that contains all your objects.
You can do Linq queries on that, as you expect to do.
You may also think of keeping your IMultipleResult as the return value of your function, but add an intermediate function that creates a structured object for you.


I hope this helps.
Regards.
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 39296933
Makes sense!

Thank you!

Tom
0
 
LVL 13

Expert Comment

by:jonnidip
ID: 39296941
You're welcome!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question