Entity references not save correctly

class PareInfo
{
    [AutoIncrement]
    public int Id { get; set; }
    public string name { get; set; }
    public int? PareInfoId { get; set; }
    [Reference]
    public PareInfo Pare { get; set; }
}

at my project, every PareInfo may have a parent,

                PareInfo p1 = new PareInfo()
                {
                    name = "p1"
                };
                PareInfo p2 = new PareInfo()
                {
                    name = "p2"
                };
          
                p1.Pare = p2;
                db.Save(p1, true);

q1:
when i saw the db, i found “p1”.pareinfoId is “p2”.id and “p2”.pareinfoId is “p1”.id , the next should be error, “p2”.pareinfoId should be null

q3:
is it only save method will auto set the Id prop? the insert method only return id and i must set manual

I am a new user for ss, I wish you can understand what i say due to my poor english,3q!

@mythz I update the issue

Sorry I can’t understand the issue from this description. I’m also not seeing what “p1” has do do with this example since it’s disconnected. The POCO definition for Node is missing making this source code incomplete and hard to follow. Can you provide the complete source code for a stand-alone failing example so I’m able to run the code and see the issue?

In answer to your other question OrmLite references support is only 1-level deep.

@mythz Hi I Edit issue

The issue was because you’re adding a reference to the same table where OrmLite will populate 1:1 references whether the FK is on the same table (self reference) or external table. Since you’re referencing the same table type it populated both. But I’ve just resolved this issue where it now only populates its own table reference in this commit.

This change is available from v4.0.61 that’s now available on MyGet.

Yes Save() is the only API that does additional custom logic like populating references and populating auto incrementing id fields. Insert() behaves as close to SQL Insert where it just inserts the record but you can fetch the auto incremented id and populate it yourself with:

var row = new PareInfo { name = "p1", PareInfoId = 2 };
row.id = db.Insert(row, selectIdentity:true);