Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Code first approach for SQLite data source

$
0
0

Hi,

I have some problem while mapping foreign key in Code first approach for SQLite.

Table:

CREATE TABLE Employees
(
    [EmployeeId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [FirstName] NVARCHAR(20)  NOT NULL,
    [ReportsTo] INTEGER,
    [Phone] NVARCHAR(24),
    FOREIGN KEY ([ReportsTo]) REFERENCES "employees" ([EmployeeId]) 
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

Class Mapping

public class Employees
    {
        [Key]
        public int EmployeeId { get; set; }       
        public string FirstName { get; set; }
        public int ReportsTo { get; set; } //
        [ForeignKey("EmployeeId")]
        public string Phone { get; set; }
    }

Error : Object reference not set to an instance of an object.

If I remove ReportTo property mapping in my Employees class it works fine. how to do ForeignKey mapping?

Thanks,


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>