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

SPMetal is creating duplicate entities when I attempt to generate code with the following conditions.

I have a custom content type [Person] that inherits from [Contact].

I have created a list instance named [Persons] and deployed it to the server.

When I run SPMetal with the following parameters.xml file I get two classes generated

[Parameters.xml]
<List Name="Persons">
  <ContentType Name="Person" Class="Person" />
</List>

[GeneratedCode.cs]
public partial class Person : Contact
public partial class Person0 : Person

Am I doing something wrong? Is there a way to simply generate one class per content type?

UPDATE:

I have determined that SPMetal is generating two classes: [Person] and [Person0] because Person is a content type but it's fields were copied to the list definition schema file when I used it in a list definition. I verified this by removing the content type, but leaving the list, SPMetal only generates one instance of the person class in this case.

Not sure where I'm going from here but wanted to update the question in case someone else was following along.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

I had the same problem and it bugged me for a bit but I found the fix. Simply remove the contenty type you have inside the list:

It seems that the content type in the list definition is there to provide an annotated class in the case that your list content type has a name that you don't prefer. I can imagine this would have other implications though; like not being able to choose which columns to include from the content type your list is inheriting from.

In the example here: http://msdn.microsoft.com/en-us/library/ee539978.aspx

It mentions that it is simply used to rename the output class.

share|improve this answer
add comment

This behavior is "By-design" and it CAN'T be overriden even if you want to. This is documented in MSDN at:

http://msdn.microsoft.com/en-us/library/ee537010.aspx

*Rules below that are marked with an asterisk cannot be overridden.

6.If a content type inherits from another content type, then the generated class that represents the former inherits from the class that represents the latter.

share|improve this answer
    
I think you've misunderstood my question. It appears that what's going on here is that Person Inherits from Contact, and the Person List Item (Person0) inherits from Person. Which is why SPMetal is creating two Person classes. Not sure how to solve this though. –  DigitalNomad Nov 4 '10 at 20:07
add comment

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.