0

I would like to write a simple one-to-one relationship between my models. The exception message I get from sqlite-net is Don't know about Profile.

public class User
{
    [PrimaryKey]
    public int pk { get; set; }

    public string first_name { get; set;}

    [OneToOne]
    public Profile profile { get; set;}

     ...
}

public class Profile
{
    [PrimaryKey]
    public int pk { get; set; }

    [ForeignKey(typeof(User))]
    public string UserID { get; set; }

    [OneToOne]
    public User user { get; set;}
}

What am I missing here? Thanks

Saphire
  • 1,812
  • 1
  • 18
  • 34

1 Answers1

1

You can see the source code here, that exception is being thrown on line 2044. If you examine the function you'll see that it's checking whether the C# type is supported and then returning the relevant SQL type.

The Profile type you are trying to add this to is not supported as it is a custom type you have created and so sqlite-net cannot know what SQL type to return for it.

Try and redesign your code so that the OneToOne relationship is only needed on supported types.

ChrisS
  • 376
  • 1
  • 11
  • Thanks! Can't I have `sqlite` create a relation table automatically? – Saphire Mar 15 '16 at 13:44
  • I'm afraid I'm not an expert in this area, but it looks like from the answer [here](http://stackoverflow.com/a/29005182/6017401) that there may be a way to do what you require. – ChrisS Mar 15 '16 at 13:51