This project has moved and is read-only. For the latest updates, please go here.

Project SPListItem to a strongly typed class

Mar 28, 2013 at 2:48 PM
I'm completely new to SharePoint, so you'll have to forgive me if this is a completely ridiculous idea, however, I'm going to ask anyway.

How hard would it be to use strongly typed classes to generate the query rather than basing everything off of SPListItem?

Instead of
var caml =
        .Where(x => (string)x["Status"] == "New")
I'm thinking something like
        .Where(x => x.Status == "New")
MyClass would look something like
    public class MyClass
        public string Status { get; set; }
Because Where takes an Expression, it shouldn't be hard to extract the property Name or Type.

I was going to look how you are building the CAML to see how feasible this is, but I get an error on the Source Code page. Not sure if that is a CodePlex issue or something on your end.
Mar 30, 2013 at 7:27 AM
Edited Mar 30, 2013 at 7:37 AM
hi cadrell0,
this is interesting idea. But use case is not very clear at the moment. If we are talking about SPMetal strongly-generated class, then most probably developers will use Linq 2 Sharepoint. So probably this feature will help in situations when we create POC class and map SPListItem to it by ourselves (I don't think people will create strongly-typed classes which will be only used for writing strongly-typed queries with Camlex). Do you have other scenarios, where this feature will help?

In general it should be possible to implement it, although I can't say at the moment how easy it will be. For SPListItem we currently use indexer operations, so we will need to add support for retrieving property names. Will add this feature to the [Future improvements]( improvements), but there are other features in the queue now. You may send pull requests and I will review it.

I've just tried to download the source code (from Source code) - it works. So may be it was temporary problem on Codeplex.