I am trying to create a very basic test project to see if I can query content hub using linq as the documentation suggests and am having some trouble.
I have created a .net5 console application and added the StyleLabs.M.Sdk.WebClient 4.1.1 nuget package from a nuget source configured for https://slpartners.myget.org/f/m-public/api/v3/index.json.
For my first attempt, visual studio complains:
'Query' does not contain a definition for 'Take'...
I tried adding the StyleLabs.M.Querying.Linq nuget package, but when I attempt to add the package, package manager complains:
Unable to find package Sitecore.Quince.Utilities. No packages exist with this id in source(s) (...)
Next I tried adding StyleLabs.M.Base.Querying 3.3.26. This restored successfully, and Take
was now accepted as an extension to Query
. But instead, Query
became the problem!
The type
Query
exists in both StyleLabs.M.Base.Querying and StyleLabs.M.Sdk
I'm tearing my hair out here. I already do have a project that uses the non-linq query methods, but I am attempting to follow the documentation's recommendation.
If I remove the WebClient namespaces I no longer get a conflict, but if I remove those namespaces then I don't have a client.. so... shrug!
using System;
using System.Linq;
using Q = Stylelabs.M.Base.Querying;
using Stylelabs.M.Base.Querying.Linq; // visual studio indicates this is not being used
using WCA = Stylelabs.M.Sdk.WebClient.Authentication;
using WC = Stylelabs.M.Sdk.WebClient;
internal class Program
{
private static void Main(string[] args)
{
var grant = new WCA.OAuthPasswordGrant { /**/ };
var client = WC.MClientFactory.CreateMClient(new Uri(""), grant);
var query = Q.Query.CreateQuery(entities =>
from e in entities
select e).Take(10);
}
}
With only the StyleLabs.M.Sdk.WebClient 4.1.1 package added, I get
'Query' does not contain a definition for 'Take' and no accessible extension method 'Take' accepting a first argument of type 'Query' could be found (are you missing a using directive or an assembly reference?)
With the StyleLabs.M.Sdk.WebApiClient 3.1.4 also added, I get
The type 'Query' exists in both 'Stylelabs.M.Base.Querying, Version=3.1.3.0, Culture=neutral, PublicKeyToken=null' and 'Stylelabs.M.Sdk, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null'
Blockquote
Help? Ideally, what I'd like is a list of the very first few steps to follow once I have, say, a bare console application created. Like:
- Add the insert specific package name and version here nuget package.
- Add the insert another specific name and version here nuget package
- ...
- Add
using ...
- call
MClientFactory.CreateMClient(..)
- Create the query object using
Query.CreateQuery(...)
using
statements, its hard to know the actual problem. But my guess is that one of yourusing
namespaces is giving you the wrongQuery
static object or you don't have the requiredusing
statement that contains theCreateQuery
extension method.IWebMClient
vsIMClient
. My existing (non linq) solution usesIWebMClient
. There may also be issues created by package versioning... I have the latest stable for all of the packages, but if I downgrade webclient to 3.. I get different behaviour.