activa / iridium

Iridium - Lightweight .NET ORM for mobile, desktop and server applications
MIT License
22 stars 8 forks source link

Iridium.DB.SchemaException: Could not create relation Fallow.Posts #15

Closed rambod17 closed 6 years ago

rambod17 commented 6 years ago
        public class DataBaseHelper : SqliteContext
        {
            private static string path = System.IO.Path.Combine(System.Environment.GetFolderPath(
     System.Environment.SpecialFolder.Personal), "Instadl.db");

            public DataBaseHelper() : base(path)
            {
            }
        public IDataSet<options> options { get; set; }
        public IDataSet<Fallow> fallows { get; set; }
        public IDataSet<Post> posts { get; set; }
        public IDataSet<InstaUserShort> instaUserShort { get; set; }
        private static DataBaseHelper _dataBaseHelper = null;

        public new static DataBaseHelper Instance
        {
            get
            {
                if (_dataBaseHelper == null)
                { 
                    _dataBaseHelper = new DataBaseHelper();
                    _dataBaseHelper.CreateTable<Fallow>(false, false);
                    _dataBaseHelper.CreateTable<Post>(false, false);
                    _dataBaseHelper.CreateTable<options>(false, false);

                }
                return _dataBaseHelper;
            }
        }

    [Table.Name("Following")]
    public class Fallow
    {
        [Column.PrimaryKey(AutoIncrement = true)]
        public long Pk { get; set; }
        public string ProfilePicture { get; set; }
        public string ProfilePictureId { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }
        [Relation.OneToMany]
        public IDataSet<Post> Posts;}
activa commented 6 years ago

Can you show the declaration of the Post class?

rambod17 commented 6 years ago
    [Table.Name("Post")]
    class Post
    {
        [Column.PrimaryKey(AutoIncrement = true)]
        public int Id { get; set; }

        public string Text { get; set; }
        public string LocalPath { get; set; }
        public string RemotePath { get; set; }
        [Relation.ManyToOne]
        public Fallow fallow { get; set; }
    }
activa commented 6 years ago

You need a way to point the Post object to the Fallow object.

So you need a field called FallowId in the Post class, and tell the relation how to link them:

    [Table.Name("Post")]
    class Post
    {
        [Column.PrimaryKey(AutoIncrement = true)]
        public int Id { get; set; }

        public int FallowId {get;set;}
        public string Text { get; set; }
        public string LocalPath { get; set; }
        public string RemotePath { get; set; }
        [Relation.ManyToOne(LocalKey="FallowId")]
        public Fallow fallow { get; set; }
    }

    [Table.Name("Following")]
    public class Fallow
    {
        [Column.PrimaryKey(AutoIncrement = true)]
        public long Pk { get; set; }
        public string ProfilePicture { get; set; }
        public string ProfilePictureId { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }
        [Relation.OneToMany(ForeignKey="FallowId")]
        public IDataSet<Post> Posts;
   }
rambod17 commented 6 years ago

not work

activa commented 6 years ago

Can you please attach a project that reproduces this?

rambod17 commented 6 years ago

https://ufile.io/7c4dp

rambod17 commented 6 years ago

Can not help me?

activa commented 6 years ago

As I said, you need to add a field called FallowId in your Post class. The test project you attached doesn't have that.

rambod17 commented 6 years ago

You are right. Thank you for your quick replay