Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Happy 2011 experts,

I have a sharepoint 2010 publishing site that I use SPMetal to generate classes to. The problem is some fields do not get generated like:

PublishingStartDate and PublishingEndDate

I tried using IncludeHiddenColumns and IncludeHiddenContentTypes parameters with no success.

Any clue?

share|improve this question
    
I tweeted a link to the question. We'll see if there are any takers. It seems like a "bug" to me as these are not protected fields, but maybe there is a workaround. –  Rob Wilson Jan 3 '11 at 0:47
    
thanks for your interest, Actually I posted the question in different websites and I got the following answer social.msdn.microsoft.com/Forums/en/sharepoint2010general/… –  Bassel Alkhateeb Jan 3 '11 at 9:57
    
Thanks for following up. –  Rob Wilson Jan 3 '11 at 19:49

4 Answers 4

up vote 3 down vote accepted

As Waldek says in http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/df7b0a20-338c-41b4-bf35-d0cfefb39dc7 - only fields based SharePoint Foundation field types are used SPMetal. The publishing field types are Server specific.

And the publishing fields are not intended for you to use directly, as you probably noticed they are not accessible in many situations (search for instance). They are meant to be used by SharePoint Server only.

But if you want to use them in CAML (contrary to what Anders says), it works pretty well, I do use it in some cases. Here's a link to get you started: http://blogs.msdn.com/b/markarend/archive/2007/01/02/caml-query-for-publishing-pages.aspx You can probably go from there and extend your SPMetal generated classes.

share|improve this answer
    
thanks for your great explanation –  Bassel Alkhateeb Jan 5 '11 at 7:23
    
yeah i got search issue mixed up with CAML issue sorry! –  Anders Rask Jan 5 '11 at 15:27

I don't have enough rep to comment, so I'll have to add this as an answer...

Try creating a new view for the list [in sharepoint designer]. Add the columns you want to this view, and set it as the default view. Then, regenerate the SPMetal classes.

Incidentally, if you're using SPMetal with linq in a publishing site with anonymous access, be prepared for trouble. It can't seem to perform certain actions such as adding items to a list, even if that list explicitly allows anonymous users to add items. I can expand on this if you'd like...

share|improve this answer

PublishingStartDate and PublishingEndDate are not "normal" fields. They cannot be queried against in CAML so it would not make sense to include it in SPMetal definitions. You also see this behaviour in Content Query Web Parts.

share|improve this answer
    
They are DateTime fields and yes you can query them through CAML because that's what I did. it makes sense to include'em for example to filter the items by date. –  Bassel Alkhateeb Jan 5 '11 at 7:21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Linq;
using Microsoft.SharePoint;


public partial class MyClass: Page, ICustomMapping
{
    const string SchedulingStartDateInternalName = "PublishingStartDate";

    private System.Nullable<System.DateTime> _schedulingStartDate;

    public System.Nullable<System.DateTime> SchedulingStartDate
    {
        get
        {
            return this._schedulingStartDate;
        }
        set
        {
            if ((value != this._schedulingStartDate))
            {
                this.OnPropertyChanging("SchedulingStartDate", this._schedulingStartDate);
                this._schedulingStartDate = value;
                this.OnPropertyChanged("SchedulingStartDate");
            }
        }
    }

    [CustomMapping(Columns = new String[] { SchedulingStartDateInternalName })]
    public void MapFrom(object listItem)
    {
        SPListItem item = listItem as SPListItem;
        if (item != null)
            this.SchedulingStartDate = item[SchedulingStartDateInternalName] as DateTime?;
    }

    public void MapTo(object listItem)
    {
        SPListItem item = listItem as SPListItem;
        item[SchedulingStartDateInternalName] = this.SchedulingStartDate;
    }


    public void Resolve(RefreshMode mode, object originalListItem, object databaseListItem)
    {
        SPListItem originalItem = (SPListItem)originalListItem;
        SPListItem databaseItem = (SPListItem)databaseListItem;

        DateTime? originalStartDateValue = originalItem[SchedulingStartDateInternalName] as DateTime?;
        DateTime? databaseStartDateValue = databaseItem[SchedulingStartDateInternalName] as DateTime?;


        if (mode == RefreshMode.OverwriteCurrentValues)
        {
            this.SchedulingStartDate = databaseStartDateValue;
        }
        else if (mode == RefreshMode.KeepCurrentValues)
        {
            databaseItem[SchedulingStartDateInternalName] = this.SchedulingStartDate;
        }
        else if (mode == RefreshMode.KeepChanges)
        {
            if (this.SchedulingStartDate != originalStartDateValue)
                databaseItem[SchedulingStartDateInternalName] = this.SchedulingStartDate;
            else if (this.SchedulingStartDate == originalStartDateValue && this.SchedulingStartDate != databaseStartDateValue)
                this.SchedulingStartDate = databaseStartDateValue;
        }
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.