Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:46:31+00:00 2026-06-06T12:46:31+00:00

I have a table with following columns: ContractorId ……… INT …………. IDENTITY ContractorName ……..

  • 0

I have a table with following columns:

ContractorId ……… INT …………. IDENTITY
ContractorName …….. Varchar(50) ……. P.K
ContractorGrade ……. Varchar(3) ……. P.K

The class generated by PetaPoco T4 template looks like this:

[TableName("contractor_master")]
[PrimaryKey("contractorname", autoIncrement=false)]
[ExplicitColumns]
public partial class contractor_master : TubewellRepo.Record<contractor_master>  
{
    [Column] 
    public int contractorid 
    { 
        get
        {
            return _contractorid;
        }
        set
        {
            _contractorid = value;
            MarkColumnModified("contractorid");
        }
    }
    int _contractorid;

    [Column] 
    public string contractorname 
    { 
        get
        {
            return _contractorname;
        }
        set
        {
            _contractorname = value;
            MarkColumnModified("contractorname");
        }
    }
    string _contractorname;

    [Column] 
    public string contractorgrade 
    { 
        get
        {
            return _contractorgrade;
        }
        set
        {
            _contractorgrade = value;
            MarkColumnModified("contractorgrade");
        }
    }
    string _contractorgrade;
  }

The code to INSERT a new record is as below:

// Insert a record
var Contractor=new contractor_master();
Contractor.contractorname = "Super Borewells";
Contractor.contractorgrade = "A";

db.Insert(Contractor);

In the second line of the Class Code, I want to know how to mention a Composite Key, which is (ContractorName + ContractorGrade).

Secondly, it is not inserting a record because it expects an Id column. Even though ContractorId is IDENTITY, it is not a primary key.

It is not INSERTING a new record and gives error because it is inserting 0 in the IDENTITY column.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:46:33+00:00Added an answer on June 6, 2026 at 12:46 pm

    My branch here: https://github.com/schotime/petapoco
    supports composite primary key by specifying the PrimaryKey attribute like:

    [PrimaryKey("ContractorName,ContractorGrade")]
    

    I’m not sure how it will work if you want the identity column there as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar),
I have a table called tblRentalRates with the following columns: rate_id (int) rate_startdate (datetime)
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have a table with the following columns: id - INT UNSIGNED AUTO_INCREMENT name
I have a table Template with following columns: ID, [Text] Suppose I have two
I have a table with following columns (name : varchar), (mydate : DATE), (endtime
I have a table with the following columns: contactId (int) interval (int) date (smalldate)
I have a table with the following columns (of urls): [id,url,visited,timestamp] Types:[int,string,int,long] I want
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
Lets say I have table with following columns 1. Client - string. 2. Profit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.