Solved

Sequence and number of calls matters?

Posted on 2013-07-01
5
305 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: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: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 500 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:knowlton
ID: 39296933
Makes sense!

Thank you!

Tom
0
 
LVL 13

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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