Solved

Sequence and number of calls matters?

Posted on 2013-07-01
5
302 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now