I have a task to make a WSP, which should provide definitions of custom list and library, but not instances. List definition has a lookup column to library item
<Field ID="{F2572330-8163-460D-9016-0AF338B2AEF5}" Name="AssignmentDocumentsLocation" Type="Lookup" Mult="FALSE" Required="FALSE" DisplayName="Documents Location" Description="Root folder for documents of assignment" StaticName="AssignmentDocumentsLocation" Group="Assignments With Documents"/>
and it's set up at run-time, when list is created by code, something like
public class CreateAssignmentsDocumentsLibrary : SPListEventReceiver
{
/// <summary>
/// A list is being added.
/// </summary>
public override void ListAdded(SPListEventProperties properties)
{
base.ListAdded(properties);
if (properties == null || properties.Web == null)
{
return;
}
var web = properties.Web;
var list = properties.List;
var listTemplate = web.ListTemplates["Assignments with documents"];
if (list.TemplateFeatureId != listTemplate.FeatureId)
{
return;
}
var libraryTemplate = web.ListTemplates["Assignments documents"];
var eventFiringEnabled = EventFiringEnabled;
EventFiringEnabled = false;
var libraryTitle = string.Format("{0} Documents", list.Title);
var library = web.Lists.TryGetList(libraryTitle);
if (library != null)
{
library.Delete();
}
var libraryDescription = string.Format("Document library for storage of {0} corresponding documents", list.Title);
var libraryId = web.Lists.Add(libraryTitle, libraryDescription, libraryTemplate);
web.Update();
library = web.Lists[libraryId];
var assignmentDocumentsLocationField =
list.Fields[new Guid("{F2572330-8163-460D-9016-0AF338B2AEF5}")] as SPFieldLookup;
assignmentDocumentsLocationField.LookupList = library.ID.ToString();
assignmentDocumentsLocationField.LookupField = "Title";
assignmentDocumentsLocationField.Update();
EventFiringEnabled = eventFiringEnabled;
}
}
When I'm trying to create a LINQ to SharePoint models with different tools (manually calling SPMetal, create list instances and click context menu item "Generate entity classes" in "Server Explorer" window, or this extension to VS) I see that models have an association attributes for lookup fields with hardcoded lists names.
So my question is: is it possible to create LINQ to SharePoint model which should handle possibility of list renaming or even situation when one website contains two or more sets of my domain list and library?