I have a list with SPFieldUser field type in it. I try to insert new item in this list using Linq 2 SP.

So, I generated data context class using the following configuration file:

<List Name="User Information List" Member="Users">
    <ContentType Name="Person" Class="PersonItem" />
<ExcludeOtherLists />
<ContentType Name="Item" Class="Item">
    <IncludeHiddenColumns />
<ContentType Name="Content type with user field" Class="BookHolder">
    <IncludeHiddenColumns />

In my data context there are PersonItem class (represent User Information List), Item class (represent Item content type), and BookHolder class (it represents my content type with SPFieldUser). SPFieldUser generated as private Microsoft.SharePoint.Linq.EntityRef<PersonItem> _bookHolderSName; (because I include User Information List in config file for spmetal as shown above). I try to insert new item in the list in this way(BookHolder item passed to function):

using (var localContext = new SPTestDataContext(webUrl)

But get the following exception - Incompatible column types. Previous type: Lookup . Current type: User. and stack trace:

at Microsoft.SharePoint.Linq.EntityTracker.ValidateMapping()
at Microsoft.SharePoint.Linq.EntityTracker.SubmitChanges(ConflictMode failureMode, Boolean systemUpdate)

Let's go to reflector.... In reflector (in ValidateMapping() method) you can see following code:

          .....<some code omitted for brevity>......
KeyValuePair<PropertyMap, SPDataField>[] array3 = array2;
            for (int i = 0; i < array3.Length; i++)
                KeyValuePair<PropertyMap, SPDataField> keyValuePair = array3[i];
                if (keyValuePair.Key.FieldType != keyValuePair.Value.FieldType && (SPDataFieldType.Text != keyValuePair.Key.FieldType || SPDataFieldType.Note != keyValuePair.Value.FieldType))
                    throw new InvalidOperationException(Resources.GetString("IncompatibleColumnTypes", new object[]

where keyValuePair.Key.FieldType is a field type from generated context, and keyValuePair.Value.FieldType - actual field type from list. As message said, I have lookup field in context, but user in actual list. But why linq generated lookup instead of User?

If this another SharePoint bug, or I missed something? And how to solve this problem? You, of course may not to generate entity for User Information List, but may be there is more convenient way?

Thanks in advance.

Your Answer

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

Browse other questions tagged or ask your own question.