Navigation
« Book update CRM 2011 | Main | Using the CRM Service via the DataContext »
Wednesday
Jun022010

Old SDK – New SDK Query by OwnerId

The latest update to the MSCRM SDK included a new LINQ provider. In this blog post we are going to compare and contrast querying for data by owner ID using the old and new SDK techniques. If you are new to the LINQ provider then you should read my quick start blog post here first.

For this example let’s assume I want to retrieve accounts where the owner ID is the current user. The following is straight from the CRM SDK and uses the lower level API calls. Keep reading past it and I will use the new LINQ provider to accomplish the same thing plus a little bit.

Guid principalId = user.UserId;

// Create a column set holding the names of the columns to be retrieved.

ColumnSet colsPrincipal = new ColumnSet();

// Set the properties of the column set.

colsPrincipal.Attributes = new string[] { "name", "accountid" };

// Create a ConditionExpression.

ConditionExpression conditionPrincipal = new ConditionExpression();

// Set the ConditionExpressions properties so that the condition is true when the

// ownerid of the account equals the principalId.

conditionPrincipal.AttributeName = "ownerid";

conditionPrincipal.Operator = ConditionOperator.Equal;

conditionPrincipal.Values = new object[1];

conditionPrincipal.Values[0] = principalId;

// Create the FilterExpression.

FilterExpression filterPrincipal = new FilterExpression();

// Set the properties of the FilterExpression.

filterPrincipal.FilterOperator = LogicalOperator.And;

filterPrincipal.Conditions = new ConditionExpression[] { conditionPrincipal };

// Create the QueryExpression.

QueryExpression queryPrincipal = new QueryExpression();

// Set the properties of the QueryExpression.

queryPrincipal.EntityName = EntityName.account.ToString();

queryPrincipal.ColumnSet = colsPrincipal;

queryPrincipal.Criteria = filterPrincipal;

// Create the request object.

RetrieveMultipleRequest retrievePrincipal = new RetrieveMultipleRequest();

// Set the properties of the request object.

retrievePrincipal.Query = queryPrincipal;

Now that we have looked at how we would have done this in the past, let’s look at what is possible using the new LINQ provider. First, you should have already read my other blog post where I talked about how to call Who Am I to get the current user ID here. For this example we startup assuming that has already been accomplished.

To make this a little more interesting, in addition to just retrieving the accounts for the user I also want to retrieve the user’s name and only the first 10 accounts.

The first thing we are going to do is build the LINQ expression that will provide the criteria for our query. The following queries for accounts that have an owner ID matching. It also shapes the results into an anonymous type that only has the properties ID and Name. Pause for a second and compare the following 7 lines, which could really be expressed as 1 line to the code we used above without the LINQ provider.

var principalQuery = from acct in ctx.accounts

where acct.ownerid.Value == currentUserID

select new

{

ID = acct.accountid,

Name = acct.name

};

Remember, the above just defines the LINQ expression it doesn’t cause execution of the query against the CRM server that will happen later when we start to enumerate the results. Next, let’s go get the user information so we can grab the full name of the user.

var userInfo =

ctx.systemusers.Where(u => u.systemuserid == currentUserID).FirstOrDefault();

If we retrieved a user the output the user name.

if (userInfo != null)

Console.WriteLine("First 10 Accounts for user " + userInfo.fullname);

Next, we are going to enumerate the accounts and print the account name. Notice that we added a Take(10) onto the LINQ query we built earlier. This will cause only the first 10 records to be used.

foreach (var acct in principalQuery.Take(10))

Console.WriteLine(" Account Name :" + acct.Name);

Hopefully it’s clear from the example the new CRM LINQ provider that’s part of the updated SDK makes it much easier to build queries against the CRM data.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (12)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: speedupmypc
    speedupmypc 2013 (full version)
  • Response
    855 You'll need 9 darkish strips and eight white strips with the weave. The only real steady that continues to be inside our kid's lives, year in, 12 months out, louis vuitton medium agenda looks being their just about phobic distaste for strolling.
  • Response
    Response: Joseph Chinnock
    CRM as a Rapid Development Platform - Journal - Old SDK - New SDK Query by OwnerId
  • Response
    Response: Belinda Broido
    CRM as a Rapid Development Platform - Journal - Old SDK - New SDK Query by OwnerId
  • Response
    CRM as a Rapid Development Platform - Journal - Old SDK - New SDK Query by OwnerId
  • Response
    Response: ezines for writers
    CRM as a Rapid Development Platform - Journal - Old SDK - New SDK Query by OwnerId
  • Response
    Response: expert advisor
    CRM as a Rapid Development Platform - Journal - Old SDK - New SDK Query by OwnerId
  • Response
    Response: Toruń
  • Response
    Response: office setup
    Get Help to Install Microsoft Office on PCs Laptops etc.Support Number 1-800-756-1088
  • Response
  • Response
    Response: qooapp download
  • Response

Reader Comments (137)

That is belstaff jackets right. Most of the clothing choices sold at RainingHollywood is the sexy and ugg cardy boots hot creations from moncler jacket Ed Hardy. You can find about three hundred hats from this get up company. You can also jimmy choo shoes expect to choose a lot of excellent things from the plenty of jeans, shirts, shorts, Uggs ireland and hoodies options that are only from Ed hardy. Naturally, there are a wide ugg canada variety of options. ugg bailey button triplet boots Whatever your style is or whatever ugg boots classic tall color you are looking for, as long it is belstaff jackets men from this prestigious clothing ugg cardy company, you are sure to find whatever you are looking for at Raining Hollywood. It is a new idea that aims to achieve both the goals of generating profits as well ugg as solving the problem of moncler jackets inequality between the rich and poor by using market forces in a better way. Several companies around the world have adopted this concept by integrating philanthropic motives with product jimmy choo shoes sale development, and treating the poor as a new class of customers. It involves a systematic approach to research, product design, distribution, partnership and profit models to help this new class of customers which businesses have traditionally ignored. LZ0916

September 16, 2011 | Unregistered Commenter1

Oh, this is quite interesting. Actulally, I found your blog on google search. I will tell my friend about your blog later.Moncler Truien Vrouwen ,Moncler Truien mannen

September 28, 2011 | Unregistered CommenterMoncler jassen

Hey! I visit your site regularly, but your blog doesn’t load on my Ipad. Could your firewall block my IP? Many thanks! Moncler jassen Vrouwen , Moncler Down Vesten Mannen,Moncler Truien mannen

September 28, 2011 | Unregistered CommenterMoncler jassen

Great! This was a really wonderful post. Thank you for your provided information.welcome you to coming us .warm winter .Moncler online,Moncler вниз Жилеты Женщины ,Moncler вниз пальто женщин,

Gucci Shoes Design of metamaterials are artificial materials, natural materials, it can not be a way to guide electromagnetic waves, such as light or magnetic field. Most recent studies are trying to make metamaterials like Harry - Potter's invisibility cloak, like the film have an effect, to guide light from around the cloak around the wearer, but the current test is only limited small objects or color range confirmed the results.shows that you can not see the object in the New Gucci light shield the magnetic field can also be the idea. Sang Chezi explained: "We are aware of these ideas are very interesting, but we do not have the final instrument, only the general concept." Autonomous University of Barcelona, he and his colleagues set out to design this "anti-magnet."

September 30, 2011 | Unregistered CommenterNew Gucci

A diameter of 6.2 million miles (about 100,000 km), equivalent to 10 times Earth's diameter is a huge sunspots solar flares, Coach Handbags the British sent a spectacular aurora show the night sky. A Star Catcher said it was his best so far to watch the aurora. Auroral particle bombardment from the sun's radiation generated when the Earth's atmosphere, usually appear only in the distant north, such as Norway. This time, as far as Northumberland Oxfordshire and other UK regions to the gorgeous view of the aurora, the night sky was illuminated by the aurora's showing a beautiful green and purple colors.Science Oxford, CEO, astronomer Ian - Dr Griffin told the British media, said: "1302 is the active zone all aurora appeared yesterday, the source may be in the next few nights there's a source of some of Aurora, according to Coach bag Space weather forecasters estimate that the next 24 hours there the possibility of more intense flares of 40% with the central disk of sunspots across the sun, any outbreak will be aligned to Earth. moonless sky, the sun coupled with an active area the next few nights of the British Star Catcher will be a very interesting concept of an empty experience."

September 30, 2011 | Unregistered CommenterCoach Handbags

Coach Handbags the British sent a spectacular aurora show the night sky. A Star Catcher said it was his best so far to watch the aurora. Auroral particle bombardment from the sun's radiation generated when the Earth's atmosphere, usually appear only in the distant north, such as Norway. This time, as far as Northumberland Oxfordshire and other UK regions to the gorgeous view of the aurora, the night sky was illuminated by the aurora's showing a beautiful green and purple colors.Science Oxford,the source may be in the next few nights there's a source of some of Aurora, according to Coach bag Space weather forecasters estimate that the next 24 hours there the possibility of more intense flares of 40% with the central disk of sunspots across the sun, any outbreak will be aligned to Earth.

September 30, 2011 | Unregistered CommenterCoach Handbags

Gucci Shoes Design of metamaterials are artificial materials, natural materials, it can not be a way to guide electromagnetic waves, such as light or magnetic field. Most recent studies are trying to make metamaterials like Harry - Potter's invisibility cloak, like the film have an effect, to guide light from around the cloak around the wearer, but the current test is only limited small objects or color range confirmed the results.shows that you can not see the object in the New Gucci light shield the magnetic field can also be the idea. Sang Chezi explained: "We are aware of these ideas are very interesting, but we do not have the final instrument, only the general concept." Autonomous University of Barcelona, he and his colleagues set out to design this "anti-magnet."

September 30, 2011 | Unregistered CommenterNew Gucci

Gucci Shoes Design of metamaterials are artificial materials, natural materials, it can not be a way to guide electromagnetic waves, such as light or magnetic field. Most recent studies are trying to make metamaterials like Harry - Potter's invisibility cloak, like the film have an effect, to guide light from around the cloak around the wearer, but the current test is only limited small objects or color range confirmed the results.shows that you can not see the object in the New Gucci light shield the magnetic field can also be the idea. Sang Chezi explained: "We are aware of these ideas are very interesting, but we do not have the final instrument, only the general concept." Autonomous University of Barcelona, he and his colleagues set out to design this "anti-magnet."

September 30, 2011 | Unregistered CommenterNew Gucci

High street Coach Outlet All Saints has been put up for Coach Outlet Online sale with price tag worth a potential £140 million, it was reported today.
The coach boots is said to have appointed Ernst & Young to advise it on the sale discount coach bags, according to The Sunday Telegraph.

All cheap jordan has 63 stores and 47 Air Yeezy Shoes across the UK, Europe, America and Russia.

The air jordans - which has been expanding rapidly in recent years - is owned by retail entrepreneur air jordan sneaker, with significant minority stakes held by collapsed Icelandic banks Kaupthing and Glitnir.

It is thought that air jordan retro of the Icelandic groups were behind the push to put All Saints up for sale to realise Derrick Rose adiZero investments in a host of UK retail assets.

British karen millen coat owned or part-owned by failed Icelandic banks - such as House of Fraser, karen millen dress chain Iceland and Karen Millen owner Aurora - are also reportedly undergoing ownership overhauls ahead of possible stake sales as Iceland gears up to capitalise on the karen millen one shoulder assets.

Ernst & Young is Chloe online shop understood to have already drawn up a list of would-be investors for All Saints, with Mr Stanford expected to roll over part or all of his stake in the event of a chloe clothes.

The chloe bags group was founded in chloe paraty python 1994 and bought by Mr Stanford in 2003.

Mr Stanford karen millen outlet also co-founded the Karen Millen chain with his ex-wife of the same name.

Neither All Saints karen millen coats nor Ernst & Young were available for comment. All guys are interested in buykaren millen dresses sale ,good enough,and fashion styles.

October 8, 2011 | Unregistered Commenterkaren millen outlet

jack00800 domestic electricity business and,north face outlet as in portals,north face outlet North Face Outlet search engines put a lot of advertis north face outlet ing. north face outlet North Face Women's Soft Shell However,north face outlet due to the continuous influx of capital,north face outlet North Face Women GoreTex Jacket competition among electricity suppliers,north face outlet the price North Face Women's Down Jackets gone up a lot of advertis north face outlet ing,north face outlet even turning North Face Women's 3 in 1 Jacket several times,north face outlet but the huge amount of advertis north face outlet ing North Face Men's Down Jackets to attract traffic,north face outlet the user can continue to buy

October 13, 2011 | Unregistered CommenterNorth Face Outlet

These kind of post are always inrefer to read quality content so I happy to find many good point here in the post

October 18, 2011 | Unregistered CommenterUGG Delaine

The question of the items to put on with ugg boots is a simple that you answer. This popular kind of UGG Womens Sundance boot are usually worn with just about anything. There are no fashion rules in regards to wearing for the reason that. In fact, it would appear UGG Ultra Tall Boots that wearing this type of boot breaks just about every fashion-related rule. Ugg boots are located in numerous colors and styles and that is that enormous selection which are boots so versatile and desirable. The styles run the gamut from the casual UGG Ultra Short Boots look from the standard three quarter's boot from a natural shade to your flamboyant and funky long-haired pink boot. Whatever color imaginable, the sheep skin might be dyed to check.

October 19, 2011 | Unregistered CommenterNew UGG Bailey Button

The question of what to put on with ugg boots is an easy someone to answer. This popular design of boot can be worn with only about anything. There isn't any fashion UGG Tasmina Slippers rules in relation to wearing mainly because. In fact, it seems that wearing this type of boot breaks just about every fashion-related rule. Ugg boots can be bought in several colors and styles and it is this enormous selection which are a pair of UGG Sundance Limited Edition boots so versatile and desirable. The styles have huge variations through the casual look with the standard three quarter's boot in the natural UGG Sundance II Boots shade to the flamboyant and funky long haired pink boot. Whatever color imaginable, sheep skin may be dyed to enhance.

October 19, 2011 | Unregistered CommenterNew UGG Bailey Button

It’s a film called Hungry for You and it’s in pre-production now. I play the lead vampire. I didn’t want to be a vampire but was forced into it so I’m struggling with my vampire powers and not wanting to turn the girl I love into a vampire. The script is really great and has a wonderful storyline. It’s been fun. The creator, Linda Andersson, has a really cool comic strip of Hungry for You that she is going to release soon. It’s sort of a teaser and a way to start the marketing for the project in a bigger level.
red bottom shoes
uggs
uggs
UGG Classic Cardy
UGG Classic Short
UGG Bailey Button Gold Leopard
UGG Classic Cardy Chocolate

November 4, 2011 | Unregistered Commenterred bottom shoes

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>