0

When a POCO has a dictionary a casting error will be thrown. Lists and other scalar properties not contained in the query will be initialized with their defaults values (Lists are correctly initialized as null) but Dictionaries aren't

Error:

Additional information: Cannot implicitly convert type 'Simple.Data.SimpleRecord' to Customer. Example: Let's say my POCO looks like this..

 public class Customer
 {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public IDictionary<AddressType, Address> Addresses { get; set; }

        public string FullName
        {
            get
            {
                return string.Concat(LastName, ", ", FirstName);
            }
        }

        public Customer()
        {
            this.Addresses = new Dictionary<AddressType, Address>();
        }
 }

Then in my DAL I have something like this... _db is the dynamic Simple.Data database object.

Let's assume that my Customer table only has the following columns: id, firstname and lastname.

 public IEnumerable<Customer> GetCustomers()
 {
      return _db.dbo.Customer.All()
            .ToList<Customer>();
 }

Has anyone come across this issue? Any workarounds?

Diego
  • 998
  • 1
  • 11
  • 20
  • Something to do with Dictionary not being serializable? – Lars Anundskås Jun 11 '14 at 14:01
  • Where's you code to convert the `Simple.Data.SimpleRecord` to a `Customer`? Have you considered using Linq-to-SQL instead of simple.data? – Rowland Shaw Jun 11 '14 at 16:14
  • The code to convert to Customer is _db.dbo.Customer.All().ToList(); Regarding Linq-to-SQL...I'm not using SQL server, I'm using PostgreSQL. However, the error in Simple.Data occurs regardless of the database implementation. – Diego Jun 11 '14 at 19:23

0 Answers0