Is it possible to retrieve SharePoint Lists by CAML request - sharepoint-2010

Could anybody help me to retrieve SharePoint Lists (NOT List Items) by CAML request using Client Side Object Model (CSOM).
I know how to get List Items using CAML query (I can use GetItems() method in a List object):
public ListItemCollection GetItems(CamlQuery query_);
I would like to do the same thing with Lists, but can't find a way, is it possible?
I'm looking for something like this:
SP.Web.GetLists(CamlQuery query)

// "ctx" is the object of client context
ListCollection lists = web.Lists;
ctx.Load(lists);
ctx.ExecuteQuery();
In object "list" you will get all list names.

Related

How to expand(odata-webapi) all the properties without passing $expand in query string in vb.net

I am using odata v5.7.0 for webapi(vb.net).I need all the properties of object should be expanded without using $expand property on the query string.
Ex: http://localhost:26209/ProductList?$expand=customers/products
into
http://localhost:26209/ProductList
Not sure why you would want to do that and there might not be a clear cut way to achive it.Still if you want to get all the products for a customer you will have to go one at a time by using something like this.
http://localhost:26209/ProductList/customers('customer_id')/products
Else if you are using OData 2 there is an EntitySet for every association, so you an directly query the products EntitySet and use $filter instead. The URL will look similar to
http://localhost:26209/Products?$filter=CustomerId eq *
You can check $filter conventions here

AppFabric - List object returned has objects with null values

I am new to AppFabric and exploring it. I am able to put List in appfabric and able to retrieve the list using Get method. However, after retrieveing all the properties of the objects are set as null. Can anybody help how can I resolve this problem.
Following is sample code
//Country object
Country country1 = new Country();
country1.Name ="test";
//Create list
List <Country> countryList = new List <Country>();
countryList.Add(country1);
//Add to AppFabric
_cache.Put("countryKey",countryList)
//Retrieve from cache
List <Country> countryList = (List <Country>)_cache.Get("countryKey");
//check the result
countryList.Count returns 1 which is expected.
countryList[0].Name returns null;
Objects are stored in the cache in a serialized form. AppFabric uses the NetDataContractSerializer class for serialization before storing the items in the cache.
Empty properties generally means that there is a problem in serialization/deserialization. Try to Add DataContract attribute to Country and DataMember attribute to each property you want to keep this class.

wcf client and sending objects to server

I have a question...
I have a web service where the OperationContract are retrieve and update.
Using a cars example, I have the retrieve providing an object that contains a list of cars and how many cars. I have that configured through a class.
[OperationContract(Name = "**Retrieve**")]
[FaultContract(typeof(FaultInfo))]
[XmlSerializerFormat]
CarInfo Retrieve(CarRequest CarRetrieve);
[OperationContract(Name = "**Update**")]
[FaultContract(typeof(FaultInfo))]
[XmlSerializerFormat]
CarUpdateInfo Update(CarUPDRequest CarUpdate);
Now the retrieve I do not seem to have a problem with at all. It's looking like it's providing the information; the update, however, is not working.
The CarUPDRequest object is defined with different classes and one of those is a list of cars.
The class is constructed much the same as the CarUpdateInfo and that seems to work.
On the client, I know I can would call the update. But I construct the object CarUPDRequest on the client.
I have the service reference namespace like CarService. I can actually type CarService. (and get the list of class methods like the CarInfo and CarUPDRequest.
A couple of things I noticed is like the .Add for a collection defined by a list. On the client app, I DO NOT get the Add. However, if I try the same thing local on the CarService.cs, it will allow me to do the add:
Example:
CarUpd.Cars.car.add doesn't work on the client but does work on the server. Work as in is an option.
When using something like
var CarUpd = new CarUpdRequest();
Is there something I am missing here?
Any assistance on this would be greatly appreciated.
I solved my issue by doing a List CarUpd = new List();

RavenDB Index created incorrectly

I have a document in RavenDB that looks looks like:
{
"ItemId": 1,
"Title": "Villa
}
With the following metadata:
Raven-Clr-Type: MyNamespace.Item, MyNamespace
Raven-Entity-Name: Doelkaarten
So I serialized with a type MyNamespace.Item, but gave it my own Raven-Entity-Name, so it get its own collection.
In my code I define an index:
public class DoelkaartenIndex : AbstractIndexCreationTask<Item>
{
public DoelkaartenIndex()
{
// MetadataFor(doc)["Raven-Entity-Name"].ToString() == "Doelkaarten"
Map = items => from item in items
where MetadataFor(item)["Raven-Entity-Name"].ToString() == "Doelkaarten"
select new {Id = item.ItemId, Name = item.Title};
}
}
In the Index it is translated in the "Maps" field to:
docs.Items
.Where(item => item["#metadata"]["Raven-Entity-Name"].ToString() == "Doelkaarten")
.Select(item => new {Id = item.ItemId, Name = item.Title})
A query on the index never gives results.
If the Maps field is manually changed to the code below it works...
from doc in docs
where doc["#metadata"]["Raven-Entity-Name"] == "Doelkaarten"
select new { Id = doc.ItemId, Name=doc.Title };
How is it possible to define in code the index that gives the required result?
RavenDB used: RavenHQ, Build #961
UPDATE:
What I'm doing is the following: I want to use SharePoint as a CMS, and use RavenDB as a ready-only replication of the SharePoint list data. I created a tool to sync from SharePoint lists to RavenDB. I have a generic type Item that I create from a SharePoint list item and that I serialize into RavenDB. So all my docs are of type Item. But they come from different lists with different properties, so I want to be able to differentiate. You propose to differentiate on an additional property, this would perfectly work. But then I will see all list items from all lists in one big Items collection... What would you think to be the best approach to this problem? Or just live with it? I want to use the indexes to create projections from all data in an Item to the actual data that I need.
You can't easily change the name of a collection this way. The server-side will use the Raven-Entity-Name metadata, but the client side will determine the collection name via the conventions registered with the document store. The default convention being to use the type name of the entity.
You can provide your own custom convention by assigning a new function to DocumentStore.Conventions.FindTypeTagName - but it would probably be cumbersome to do that for every entity. You could create a custom attribute to apply to your entities and then write the function to look for and understand that attribute.
Really the simplest way is just to call your entity Doelkaarten instead of Item.
Regarding why the change in indexing works - it's not because of the switch in linq syntax. It's because you said from doc in docs instead of from doc in docs.Items. You probably could have done from doc in docs.Doelkaartens instead of using the where clause. They are equivalent. See this page in the docs for further examples.

How does a Queryable Load work in SharePoint?

Could anybody help me to understand what kind of work is going behind the scene, when LINQ is used for retrieving SharePoint objects. For example, I can use a code like this:
private IEnumerable<List> newLists;
var dt = new DateTime(2010, 3, 20);
var query = from list
in clientContext.Web.Lists
where list.Created > dt && list.Hidden == false
select list;
newLists = clientContext.LoadQuery(query);
clientContext.ExecuteQuery();
How does it work?
How does request look like?
From documentation I found:
When you use the CSOM, you can write LINQ queries against client-side
objects, such as lists and Webs, and then use the ClientContext class
to submit these queries to the server. It's important to understand
that when you take this approach, you are using LINQ to Objects to
query SharePoint objects, not LINQ to SharePoint. This means that your
LINQ expressions are not converted to CAML and you will not see the
performance benefits that are associated with CAML conversion.
So, I was little bit confused, because I thought, that LINQ expression is transformed to Caml request. I can't understand how does it work. How can I watch details of request while executing ExecuteQuery() method? Could you please recomend me any tools for watching requests?
SP uses CAML internally: SP runtime converts Linq to CAML and send it via Soap request, or REST statement (if you are using RESTful services): http://msdn.microsoft.com/en-us/library/ff798339.aspx (with examples);
See more here:
http://msdn.microsoft.com/en-us/library/ff798464.aspx
and this can be helpful: http://nikspatel.wordpress.com/2012/08/05/sharepoint-2010-data-querying-options-server-om-vs-client-om-vs-rest-vs-linq-vs-search-api/