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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:42:43+00:00 2026-06-07T01:42:43+00:00

I have read through most every post on EF-SaveChanges and do not believe my

  • 0

I have read through most every post on EF-SaveChanges and do not believe my answer lies in any of those posts.

I am using C#, .NET 4, EF 4.3.1, SQL Server 2008R2, VS 2k11 Beta, AutoMapper.

Here is my code:

using (Model.AnimalRescueEntities context = new Model.AnimalRescueEntities())
{
    using (TransactionScope transaction = new TransactionScope())
    {
        context.Connection.Open();

        //Retrieve the event
        eventDB = context.Events.Single(e => e.ID == eventRegVM.EventID);
        eventOrgBaseDB = context.Entity_Base.Single(b => b.ID == eventDB.Entity_Organisation.ID);
        eventRegVM.Event = Mapper.Map<Model.Event, EventsViewModel>(eventDB);
        eventRegVM.Event.Entity_Organisation.Entity_Base = Mapper.Map<Model.Entity_Base, Entity_BaseViewModel>(eventOrgBaseDB);

        //saves Event_Registration
        eventRegDB = Mapper.Map<Event_RegistrationViewModel, Model.Event_Registration>(eventRegVM);
        eventRegDB.Event = eventDB;
        eventRegDB.EventID = eventDB.ID;
        eventRegDB.Event.Entity_Organisation = context.Entity_Organisation.Single(o => o.ID == eventOrgBaseDB.ID);
        eventRegDB.Event.Entity_Organisation.Entity_Base = eventOrgBaseDB;

        //Add the link between EVENT and REGISTRATION
        context.Event_Registration.AddObject(eventRegDB);
        int numChanges = context.SaveChanges();

        var regs = context.Event_Registration.Where(r => r.ID != null).ToList();
    }
}

I have SQL Profiler running in the background and when SaveChanges is called I see this SQL code (numChanges is 1):

exec sp_executesql N'declare @generated_keys table([ID] uniqueidentifier)
insert [dbo].[Event_Registration]([EventID], [DateSubmitted], [HasPaid], [PaymentMethod], [Comments], [AmountPaid])
output inserted.[ID] into @generated_keys
values (@0, @1, null, @2, null, @3)
select t.[ID]
from @generated_keys as g join [dbo].[Event_Registration] as t on g.[ID] = t.[ID]
where @@ROWCOUNT > 0',N'@0 uniqueidentifier,@1 datetime2(7),@2 int,@3 decimal(19,4)',@0='1D841F75-AEA1-4ED1-B3F0-4E3994D7FC0D',@1='2012-07-04 14:59:45.5239309',@2=0,@3=0

regs will contain three exist rows and my new row. However, I cannot run a SELECT statement in SQL Server and see my new row. Running this many times will get me the same result – three existing rows in the database and a new fourth row that will never make it to the database.

eventRegDB also contains the GUID created for the primary key, ID; I assume SQL server does this but not 100% sure of that.

I have taken the above TSQL and run it in a query window against my database – I get new rows in my Event_Registration table after that – that is how the three existing rows were created.

I see now exceptions or other errors generated and cannot find any reason this would not save to the database. Any ideas? If you want to see the schema for the SQL, how to recreate the database, the code (any or all), then ask – this is all hosted on http://animalrescue.codeplex.com/ but I haven’t stored this code, yet.

  • 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-07T01:42:44+00:00Added an answer on June 7, 2026 at 1:42 am

    You are missing transaction.Complete() so your transaction is never committed. When the using block for TransactionScope completes your transaction is rolled back.

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

Sidebar

Related Questions

Have read through the MSDN naming guidelines and could not find a clear answer,
I have read through several articles which are alternatives to using setpixel/getpixel but I
Okay guys, I have read through all the other posts and question on jQuery
This is probably not a dup; I have read through many similar problems on
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation
I've read through a number of topics now and have not found one quite
I know there are several estimating questions here, and I have read through most
I have read through about every possible solution online, and I get a different
I have read through the follow SO articles C#: How do I call a
I have read through the Rails docs for Routing , Restful Resources , and

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.