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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:24:54+00:00 2026-05-24T19:24:54+00:00

I have some code that is a result of pretty much my first effort

  • 0

I have some code that is a result of pretty much my first effort to do TDD for an actual work project. Attempting to bootstrap, I created an entity model and tests that assert the presence of data records required materialize a report, the first concrete goal I have identitfied.

I thought it was working reasonably well until I found code that looks like it has a bug, and YET test still passes.

Here are the snippetts: The bug (I think) is a missing call to AddObject().

If anyone has the patience/inclination to look at the whole thing, I pasted it into a gist.

Test Code:

TestFactory target = new TestFactory(@"data source=biz2\da;initial catalog=DirectAgents;integrated security=True;");
DirectAgentsEntities actual = target.Create();
Assert.IsNotNull(actual);

var advertisers = actual.Advertisers.OrderBy(c => c.Id).ToList();
Advertiser advertiser1 = advertisers.ElementAt(0);
Assert.AreEqual("Advertiser 1", advertiser1.Name);

Implementation Code:

 public TestFactory(string connectionString)
 {
     this._connectionString = connectionString;
 }

 public DirectAgentsEntities Create()
 {
    CleanUp(this.DirectAgentsEntities);
    AddAdvertiserClients();
    var db = this.DirectAgentsEntities;
    return db;
}
private void AddAdvertiserClients()
{
    var db = this.DirectAgentsEntities;
    Advertiser a;
    a = new Advertiser
    {
        Name = "Advertiser 1",
        Client = db.Clients.First(c => c.Name == "Client 1")
    };
    db.SaveChanges();
}
private DirectAgentsEntities DirectAgentsEntities
{
    get
    {
        string entityConnectionFormat = @"metadata=res://*/Formss.AB2.Model.ABModel.csdl|res://*/Formss.AB2.Model.ABModel.ssdl|res://*/Formss.AB2.Model.ABModel.msl;provider=System.Data.SqlClient;provider connection string=""{0};multipleactiveresultsets=True;App=EntityFramework""";
        string entityConnectionString = String.Format(entityConnectionFormat, _connectionString);
        return new DirectAgentsEntities(entityConnectionString);
    }
}
private string _connectionString;

How can the row get added without a call to AddObject? Should I look closer at my code for a subtle bug?

  • 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-24T19:24:55+00:00Added an answer on May 24, 2026 at 7:24 pm

    I believe you are saying that you feel an AddObject is needed after creating the Advertiser?
    If I have misunderstood the question, my apologies.

    When you link the Advertiser to a Client, what is happening in the generated code is that the Advertiser is also being added to the Client.Advertisers collection at the other side of the relationship.
    This gets noted as a change on the Client object and saved by the SaveChanges call.

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

Sidebar

Related Questions

I have a problem that annoys me pretty much. I'm grabbing some content from
I have some pretty simple code that reads lines from a network stream that
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program
I have some code that I am putting in the code-behind of a master
I have some code that uses the Oracle function add_months to increment a Date

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.