1

由于我将我的 Visual Studio for Mac 2017 升级到 2019,我无法在我的真实设备上运行我的 Xamarin.iOS 应用程序。

我使用与模拟器相同的数据库,但总是出现异常OneToMany relationship destination must have Foreign Key to the origin class

由于我升级到 VS 2019,我不得不更改 IOS 构建设置(链接器行为:链接全部 | 未选中启用增量构建)。

我的代码没有改变,但在我的设备上的第一次 db 调用中失败了。

Nuget 包: SQLiteNetExtensions 2.1.0 sqlite-net-pcl 1.5.231 sqlitePCLRAW.Core 1.1.13

我也会展示我的代码,但由于它已经工作了一年多并且仍在模拟器上工作,我认为错误不存在。

存储库:

        using (var db = ConnectionHelper.GetConn())
        {
            var resul = db.GetAllWithChildren<CompanyDataModel>().ToList();
            return resul;
        }

错误: 已抛出 SQLiteNetExtensions.Exceptions.IncorrectRelationshipException

CompanyDataModel.Functions:OneToMany 关系目标必须具有原始类的外键

课程:

public class CompanyDataModel
{
    [PrimaryKey, AutoIncrement, Column("ID")]
    public long ID { get; set; }
    public string Name { get; set; }
    public ColorType ColorType { get; set; }
    [OneToMany(CascadeOperations = CascadeOperation.All)]
    public List<FunctionDataModel> Functions { get; set; }
    [OneToMany(CascadeOperations = CascadeOperation.All)]
    public List<LocationDataModel> Locations { get; set; }

    public CompanyDataModel()
    {
        Functions = new List<FunctionDataModel>();
        Locations = new List<LocationDataModel>();
    }
}


public class FunctionDataModel
{
    [PrimaryKey, AutoIncrement, Column("ID")]
    public long ID { get; set; }
    public string Name { get; set; }
    [ForeignKey(typeof(CompanyDataModel))]
    public long CompaniesID { get; set; }
    [ManyToOne]
    public CompanyDataModel Company { get; set; }
}

public class LocationDataModel
{
    [PrimaryKey, AutoIncrement, Column("ID")]
    public long ID { get; set; }
    public string Name { get; set; }
    [ForeignKey(typeof(CompanyDataModel))]
    public long CompaniesID { get; set; }
    [ManyToOne]
    public CompanyDataModel Company { get; set; }
}
4

0 回答 0