?
Solved

Sequence and number of calls matters?

Posted on 2013-07-01
5
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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