views:

29

answers:

1

Ok, I'll explain this as much as I can...

I've got a Site Lookup Column called EEE Content Type which refers to the Site Content Item Type Types List.

Now in my custom list (which inherits from Item), I am referencing that column, and it comes up in sharepoint fine and displays the lookup values.

The issue is when I'm using SPMetal.exe to generate the types it whinges about "Key isn't present in the dictionary" and fails. So I remove the definition of the column in the parameters.xml file for SPMetal, and re-generate the classes.

Now I've manually added the property and association.

private EntityRef<SiteContentItemTypeItem> _eeeContentType;
[Association(Name = "EEE_x0020_Content_x0020_Type", Storage = "_eeeContentType", MultivalueType = AssociationType.Single, List = "Site Content Item Types")]
public SiteContentItemTypeItem EEEContentType
{
    get
    {
        return this._eeeContentType.GetEntity();
    }
    set
    {
        this._eeeContentType.SetEntity(value);
    }
}

SiteContentItemTypeItem inherits from Item so its class is empty.

But when I load the custom list I have created, i get the first entry and the EEEContentType field is null...

using (IntranetDataContext context = new IntranetDataContext("http://siteurl")) {
    context.ObjectTrackingEnabled = false;

    EntityList<SiteContentItem> alerts = context.GetList<SiteContentItem>("User Alerts");
    SiteContentItem alert = (from tmpalert in alerts where tmpalert.Id == 1 select tmpalert).First();
    SiteContentItemTypeItem contentType = alert.EEEContentType;
}

I'm all out of ideas...

Should the List value in the Association attribute be that of a collection in the class or is it refering to the actual lookup list name?

+1  A: 

Figured it out...

Stupid of me to "assume" when creating site lookup columns via code that SharePoint would use the proper naming conventions for FieldNames with spaces.

So the fieldName was correct, its InternalName wasn't the one I was expecting. And as sharepoint linq requires the internal names, it was throwing internal exceptions in the Linq.SharePoint DLL.

ChrisWalshie