Micro ORM Dapper Could not find the key property for type

1.1k Views Asked by At

I am new to Micro-ORM i am using dapper fluent mapping and dommel I try to insert/add entries but I encounter this error "Could not find the key property for type" here is my Code

        using (IDbConnection con = new MySqlConnection(cnxStr))
        {
            con.Open();
            equipment eqp = new equipment 
            {
                category_id     = 1, 
                barcode         = "DDH-003",
                asset_number    = "45645645", 
                equipment_name  = "DBD Dew", 
                equipment_description = "Thin Can", 
                manufacturer_id = 3, 
                model           = "Blah", 
                serialnumber    = "11111", 
                status          = "Good", 
                service_group   = "SGE", 
                required_pm     = "Yes", 
                service_provider="111", 
                frequency       = 1, 
                department_id   = 1, 
                location_id     = 1, 
                availability    = "Avail", 
                register_id     = 1, 
                supplier_id     = 1, 
                conditionstatus_id = 1, 
                status_id       = 1, 
                utilization_id = 3
            };
            int count = con.Insert<equipment>(eqp); <-- error here
            if (count > 0) 
            {
                MessageBox.Show("Successfully Added", "Successfully Added -:", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            }
            con.Close();

        }
1

There are 1 best solutions below

0
Nash On BEST ANSWER

Dapper assumes you have a column named Id in your db model, unless you specify otherwise. In this case, on the other hand, you are using an extenstion from Dapper.Contrib. For this to work you have to add a directive [key] above your primary key.