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 6698277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:33:33+00:00 2026-05-26T06:33:33+00:00

I have two table Subscription and PackageType. Subs has FK as PackageTypeId. Now when

  • 0

I have two table Subscription and PackageType. Subs has FK as PackageTypeId. Now when I am inserting a new record in Subscription table using EF 4.1 it is throwing an exception

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Subscription_PaymentType". The conflict occurred in database “MyDatabaseName”, table "dbo.PaymentType", column 'Id'.
The statement has been terminated.

Tables information are:

Subscription Table:

   Id  (PK)

   PaymentTypeId (FK)

   Period

   date 

PaymentType:

   Id (PK)

   Name

And the Code is as given below:

    public void Proceed(SubscriptionSessionData data)
    {

        if (data != null)
        {
            PMSCatalogEntities entities = new PMSCatalogEntities();

                Subscription subs = new Subscription();
                subs.Id = Guid.NewGuid();
                subs.ApplicableFrom = data.ApplicableFrom;
                subs.TenantId = tenant.Id;

                subs.PackageId = data.PaymentType;
                subs.PaymentTypeId = data.PaymentType;

                entities.AddToSubscriptions(subs);
                entities.SaveChanges();

        }
  }

Any idea about this issue?

  • 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-05-26T06:33:34+00:00Added an answer on May 26, 2026 at 6:33 am

    I have already tested this scenario and it works great:

        class Program
        {
            static void Main(string[] args)
            {
                PMSCatalogEntities entities = new PMSCatalogEntities();
    
                Subscription subs = new Subscription();
                subs.Id = Guid.NewGuid();
                subs.Date = DateTime.Now;
                subs.PaymentId = 1;
    
                entities.Subscriptions.Add(subs);
                entities.SaveChanges();
            }
        }
    
        public class PMSCatalogEntities : DbContext
        {
            public DbSet<Subscription> Subscriptions { get; set; }
    
            public DbSet<Payment> Payments { get; set; }
    
        }
    
        public class Subscription
        {
            public Guid Id { get; set; }
    
            public DateTime Date { get; set; }
    
            public Payment Payment { get; set; }
    
            public int PaymentId { get; set; }
        }
    
        public class Payment
        {
            public int Id { get; set; }
    
            public string Type { get; set; }
        }
    

    And on the DB

    TABLE [dbo].[Payments](
        [Id] [int] IDENTITY(1,1) NOT NULL,
        [Type] [nvarchar](max) NULL,
    
    TABLE [dbo].[Subscriptions](
        [Id] [uniqueidentifier] NOT NULL,
        [Date] [datetime] NOT NULL,
        [PaymentId] [int] NOT NULL,
    

    The only thing I have to be sure is that a Payment with Id 1 for this example is persisted on the Payments table, and it works like a charm!!

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

Sidebar

Related Questions

I have two table TABLE_EXAM and TABLE_QUESTION. I fetch record using following code but
I have two table first is TABLE_SUBJECT and second is TABLE_CHAPTER.Now i want to
I have two table to be joined using hbm file. The scenario is as
I have two table in my mysql database and when I add a new
I have two table cpuinfo and jobinfo. I want to create report using both
I have two dates in my subscription table ( start_date and end_date ). I
I have two table category and subcategory I am trying to delete record from
I have two tables with relation: modelBuilder.Entity<User>() .HasOptional(u => u.Subscription) .WithMany(); how can I
I have two table views, when user clicks one cell of the first, second
I have two table cells, with dynamic content. Table cell one works fine, when

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.