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'm not sure if I have found a bug here or if I'm doing something wrong.

I have a list which I provision using a SPI in Visual Studio, in the List Instance XML I provision some default list items using the Data Element (see code snippet below):

   <Data>
  <Rows>
    <Row>
      <Field Name="Title">myItem</Field>
      <Field Name="Key">myItem</Field>
      <Field Name="Value">myValue</Field>
    </Row></Rows></Data>

The list items above are of a particular Content Type which has been added to the list. I then generated the entity classes for my list and content type by running SPMetal. In a web part I have the following code which queries the list using Linq to SharePoint -

 DataContext context = new DataContext(SPContext.Current.Site.RootWeb.Url);

        // Get the config items
        EntityList<ConfigItem> configItems = context.GetList<PhoneBookConfigItem>("Config List");

        // Query for the config item
        var items = from configItem in configItems
                        where configItem.Key == "myItem"
                  select configItem;

        string value = item.Value;

The problem is that the EntityList count is always empty. If I got to the list and edit the item and re-query it seems to pickup the one item. If I add new items to the list via the UI I can query successfully for those items.

It's almost like they have not been written to the database correctly when provisioned through the List Instance. Has anyone seen this issue before? it's quite frustrating as you can imagine!

Cheers,

Alex

share|improve this question
add comment

1 Answer

"PhoneBookConfigItem" is the default contenttype of your list? if not, your listinstanse xml missing the ContentType Field

<Data>
  <Rows>
   <Row>
     <Field Name="ContentType">PhoneBookConfigItem</Field>
     <Field Name="Title">myItem</Field>
     <Field Name="Key">myItem</Field>
     <Field Name="Value">myValue</Field>
   </Row>
  </Rows>
</Data>
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.