0

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

1 Answer 1

1

"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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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