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?


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;

    public void MapTo(object listItem)
       SPListItem item=(SPListItem) listItem;

    //New property declaratin go here
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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