1

I have a list MyList based on ContentType MyContentType in Sharepoint.

Now I try to generate the LINQ classes with SPMetal but the class for ContentType is created twice basically.

XML config for SPMetal

<?xml version="1.0" encoding="utf-8"?>
<Web AccessModifier="Internal" xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
   <List Name="MyList">
       <ContentType Name="MyContentType"></ContentType>
   </List>
  <ExcludeOtherLists/>
  <ExcludeOtherContentTypes/>
</Web>

Parts of output cs file

[Microsoft.SharePoint.Linq.ListAttribute(Name="MyList")]
public Microsoft.SharePoint.Linq.EntityList<MyContentTypeMyContentType> MyList {
    get {
        return this.GetList<MyContentTypeMyContentType>("MyList");
    }
}

[...]

[Microsoft.SharePoint.Linq.ContentTypeAttribute(Name="MyContentType", Id="0x01003D132021D84A48E9A16011B7648CBD98")]
[Microsoft.SharePoint.Linq.DerivedEntityClassAttribute(Type=typeof(MyContentTypeMyContentType))]
internal partial class MyContentType : Element {
    [...]
}

[...]

[Microsoft.SharePoint.Linq.ContentTypeAttribute(Name="MyContentType", Id="0x01003D132021D84A48E9A16011B7648CBD98", List="MyList")]
internal partial class MyContentTypeMyContentType : MyContentType {
    public MyContentTypeMyContentType() {
        this.OnCreated();
    }
}

As you can see it generates a MyContentTypeMyContentType class derived from MyContentType. But why? Its useless. How can I avoid this behaviour?

It would be correct if MyList would just be an EntityList of MyContentType instead of MyContentTypeMyContentType.


PS

If I add a class name in the XML config for the ContentType like this:

<ContentType Name="MyContentType" class="MyContentType"></ContentType>

It still generates a second class and names it MyContentType0 which is wrong as well.

Marc
  • 6,749
  • 9
  • 47
  • 78
  • Did you ever find a solution for this? Sounds like the same issue as http://stackoverflow.com/questions/4407066/spmetal-generates-doubled-entity-names-entity-entityentity. – stephenl Feb 04 '13 at 07:01
  • No I had to remove Linq from the project because Linq-to-Sharepoint in a sandboxed solution is a huge performance problem (as the context has to be created on every request) – Marc Feb 04 '13 at 13:09
  • 1
    Fair enough. I think I found a couple of reasons why this is happening. Basically, one of our developers had set the Inherits property on the content type to false. This causes the generator to create the extra class with the double name with properties that threw exceptions saying the Title property was removed. Other causes included missing field declarations for properties defined in content type and invalid declarations. I'm finding L2SP to be rather useful for validating your declarations. – stephenl Feb 04 '13 at 22:30

0 Answers0