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

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" />
  </List>
<ExcludeOtherLists />
<ContentType Name="Item" Class="Item">
    <IncludeHiddenColumns />
</ContentType>
<ContentType Name="Content type with user field" Class="BookHolder">
    <IncludeHiddenColumns />
</ContentType>

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)
{
   localContext.Users.Attach(item.BookHolderSName);
   localContext.GetList<BookHolder>(ListTitle).InsertOnSubmit(item);
   localContext.SubmitChanges();
}

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[]
                    {
                        keyValuePair.Key.FieldType, 
                        keyValuePair.Value.FieldType
                    }));
                }
            }

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.

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.