Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm trying to populate a model using the following query:

[Table("rate")]
public class Rate : BaseModel
{
    [PrimaryKey("id", false)]
    public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; }
 
    [Column("type")]
    public string Type {get; set; }
    
    [Reference(typeof(Supplier))
    public Supplier Supplier {get; set;}
}
[Table("supplier")]
public class Supplier : BaseModel
{
    [PrimaryKey("id")] //uuid 
    public string Id { get; set; }

    [Column("name")]
    public string Name { get; set; }
}
var result = await _client
      .From<Models.Rate>()
      .Get();

But I'm recieving this Newtownsoft error message:
Newtonsoft.Json.JsonSerializationException: 'Error converting value "cc8c5124-fd48-4f40-beb9-b85d9b9cc5b4" to type 'Models.Supplier'. Path '[0].Supplier.`

I can see uuids are used with Reference/TypeOf in some of the examples so not sure why this isn't working? Using Newtownsoft 13.0.3.

Any assistance would be appreciated, have spent half a day trying to get figure this out...

You must be logged in to vote

Replies: 2 comments

Comment options

Managed to solve this shortly after posting 🤦‍♂️

Adding the column property to the Reference fixes the issue. Column name is for the target column:

[Table("rate")]
public class Rate : BaseModel
{
    [PrimaryKey("id", false)]
    public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; }
 
    [Column("type")]
    public string Type {get; set; }
    
    [Reference(typeof(Supplier))]
    [Column("id")] //Column name to map too in Supplier
    public Supplier Supplier {get; set;}
}

I don't know why this works as it seems to work for other References that use Int etc. Guessing so its gets parsed correctly?

You must be logged in to vote
0 replies
Comment options

Good that you solved it, uuid should also be parsed as Guid in Csharp

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.