scale-tone / linq2dynamodb

A type-safe data context for AWS DynamoDB with LINQ and in-memory caching support. Allows to combine DynamoDB's durability with cache speed and read consistency
MIT License
42 stars 24 forks source link

Cannot have List<string> as property type #47

Closed megyfexid closed 6 years ago

megyfexid commented 7 years ago

If I try to use List<string> as a property type I get: 'System.InvalidCastException' in Linq2DynamoDb.DataContext.dll Unable to cast object of type 'Amazon.DynamoDBv2.DocumentModel.DynamoDBList' to type 'Amazon.DynamoDBv2.DocumentModel.PrimitiveList'. at lambda_method(Closure , DynamoDBEntry ) at Linq2DynamoDb.DataContext.Utils.DynamoDbConversionUtils.ToObject(Document doc, Type entityType) at Linq2DynamoDb.DataContext.ReaderBase1.<.ctor>b__0_0(Document doc) at Linq2DynamoDb.DataContext.ReaderBase1.SetCurrent(Document doc) at Linq2DynamoDb.DataContext.TableDefinitionWrapperBase.SingleDocReader1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at webapi.Controllers.ArticlesController.d__2.MoveNext() in C:\Projects\angular4-seed\webapi\Controllers\ArticlesController.cs:line 62

My class looks like this:

public class Customer
  {
    public Guid CustomerId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    //couldn't use List<string> because linq2dynamodb has a bug
    public List<string> ApproverProfTypes { get; set; }
  }

The workaround at the moment is to wrap the string in another class:

public class Customer
  {
    public Guid CustomerId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    //couldn't use List<string> because linq2dynamodb has a bug
    public List<ProfTypes> ApproverProfTypes { get; set; }
  }

public class ProfTypes
{
public string ProfType { get; set; }
}
megyfexid commented 7 years ago

I get the error when calling this: var approver = ctx.Customer.Where(c => c.CustomerId == ArticlesDataContext.loggedInCustomerId).ToList().First();

scale-tone commented 7 years ago

We even have a test for List(string) fields, and it passes.

Can you elaborate on how you created that particular DynamoDB record you're trying to read? Was it created by Linq2DynamoDB or by some external code? Or manually maybe? Can you please show the JSON of that record? Can you please try to create that record with Linq2DynamoDB and try to read it?

scale-tone commented 6 years ago

No sound from the author, so closing this.