Trevor
Trevor

Reputation: 1604

SharpRepository: XmlRepository implementation

Very simple question so I hope this doesn't get me shot to pieces on Stack.

I am trying to get to grips with the cool SharpRepository package however I have been unsuccessful in finding any useful information on how to impelement the XmlRepository assembly that is bundled with it.

Actually I speak a lie, the nuget version doesn't have it, the github version does but my crap attempts at trying to use it failed.

I compiled the github source then added a reference to SharpRepository.Repository and SharpRepository.XmlRepository, so far so good.

I then did a very simple test by first created a basic entity (name, address, postcode) and then did a quick test as follows:

var repo = new XmlRepository<Client, string>("C:\client.xml");

When I debug the console app and step into the source code on that line, drill down to the base class XmlRepositoryBase.cs and step through the method LoadItems() I get the an error when I try to execute the line

_items = (List<T>)serializer.Deserialize(reader);

I get the following error message:

<client xmlns=''> was not expected.

The class is very simple for the sake of testing:

public class Client
{
   public Int32 Id { get; set; }
   public String Name { get; set; }
   public String Postcode { get; set; }
}

The XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<client>
  <clientProfile>
    <id>1</id>
    <name>TheFragranceShop</name>
    <description>The Fragrance Shop</description>
    <enabled>true</enabled>
  </clientProfile>
</client>

Thanks in advance and if I manage to work it out will post an update.

Upvotes: -1

Views: 141

Answers (1)

Trevor
Trevor

Reputation: 1604

I received an answer from the authors:

The XmlRepository is here: http://www.nuget.org/packages/SharpRepository.XmlRepository/1.3.5.18-unstable

It is marked as pre-release only because it hasn't been used a lot in the real world (as far as I can tell). I've used it for simple things like storing a small amount of data for simple desktop apps, etc.

It is meant to be used with POCO objects and will store the collection of objects in a single XML file (1 per repository type). It is not meant to be used for querying existing random XML files, so if that is your purpose then it won't work for you.

Jeff

This makes sense so I am going to use some of the answers already posted on Stack regarding this subject such as:

Creating an Entity from XML

I think the best solution will be to use a combination of Linq to XML and XML Serli

Upvotes: -1

Related Questions