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

If I generate .cs file using SPMetal for my site and then use it in Visual Studio to develop web part using Linq. And later on I create a new list in my site, will I need to generate .cs file again?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Short answer is "Unfortunately, yes, you have to generete .cs files again".

After changing the list structure you need to regenerate cs files or create custom mapping.

Piece of code from Joerg Krause "SharePoint 2010 as a Developer Platform" (by the way, it is a very nice book and I advice you to buy and read it if you haven't read it yet):

public partial class Book: ICustomMapping
{
    [CustomMapping(Columns=new String[]{"ISBN","UPCA"})]
    public void MapFrom(object listItem)
    {
       SPListItem item=(SPListItem) listItem;
       this.ISBN=item["ISBN"];
       this.UPCA=item["UPCA"];
    }

    public void MapTo(object listItem)
    {
       SPListItem item=(SPListItem) listItem;
       item["ISBN"]=this.ISBN;
       item["UPCA"]=this.UPCA;
    }

    //New property declaratin go here
}
share|improve this answer
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.