C# syntax error - beginner needs help

I'm following a tutorial:  https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-webforms-app-membership-oauth-sql-database/

I'm at a step that has me modifying the Migrations > Configurations.CS

Tutorial says:

4.Open the Migrations\Configuration.cs file.


5.Add the following namespace:
using ContactManager.Models;

Open in new window


6.Replace the Seed method with the following code:
protected override void Seed(ContactManager.Models.ApplicationDbContext context)
{
    context.Contacts.AddOrUpdate(p => p.Name,
       new Contacts
       {
           ContactId = 1,
           Name = "Ivan Irons",
           Address = "One Microsoft Way",
           City = "Redmond",
           State = "WA",
           Zip = "10999",
           Email = "ivani@wideworldimporters.com",
       },
       new Contacts
        {
            ContactId = 2,
            Name = "Brent Scholl",
            Address = "5678 1st Ave W",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "brents@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 3,
            Name = "Terrell Bettis",
            Address = "9012 State St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "terrellb@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 4,
            Name = "Jo Cooper",
            Address = "3456 Maple St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "joc@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 5,
            Name = "Ines Burnett",
            Address = "7890 2nd Ave E",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "inesb@wideworldimporters.com",
        }
        );
}

Open in new window

After adding one line and replacing visual studio points several places as syntax errors

Here's combined code that has syntax errors
namespace ContactManager.Migrations
{
    using ContactManager.Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<ContactManager.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            protected override void Seed(ContactManager.Models.ApplicationDbContext context)
{
    context.Contacts.AddOrUpdate(p => p.Name,
       new Contacts
       {
           ContactId = 1,
           Name = "Ivan Irons",
           Address = "One Microsoft Way",
           City = "Redmond",
           State = "WA",
           Zip = "10999",
           Email = "ivani@wideworldimporters.com",
       },
       new Contacts
        {
            ContactId = 2,
            Name = "Brent Scholl",
            Address = "5678 1st Ave W",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "brents@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 3,
            Name = "Terrell Bettis",
            Address = "9012 State St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "terrellb@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 4,
            Name = "Jo Cooper",
            Address = "3456 Maple St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "joc@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 5,
            Name = "Ines Burnett",
            Address = "7890 2nd Ave E",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "inesb@wideworldimporters.com",
        }
        );
}
            AutomaticMigrationsEnabled = false;
            ContextKey = "ContactManager.Models.ApplicationDbContext";
        }}}
}

Open in new window


Thanks in advance
LVL 5
volkingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
it looks like you are trying to put a whole method in your constructor... can't do that.
 public Configuration()
        {
         }
            protected override void Seed(ContactManager.Models.ApplicationDbContext context)
             {}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_saigeDeveloperCommented:
You have placed the Seed implementation logic into the Configuration constructor; this is illegal.

In other words:
using System;

namespace EE_Q28738695
{
	class Program
	{
		static void Main(string[] args)
		{
			// This is the method call
			Write2Plus2();
			Console.ReadLine();
		}

		// This is the method implementation
		static void Write2Plus2()
		{
			Console.WriteLine("2 + 2 = {0}", 2 + 2);
		}
	}
}

Open in new window

Produces the following output -Capture.JPGWhat you probably wanted to do was something like:
using ContactManager.Models;
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;

namespace ContactManager.Migrations
{
	internal sealed class Configuration : DbMigrationsConfiguration<ContactManager.Models.ApplicationDbContext>
	{
		public Configuration()
		{
			Seed();
			AutomaticMigrationsEnabled = false;
			ContextKey = "ContactManager.Models.ApplicationDbContext";
		}

		protected override void Seed(ContactManager.Models.ApplicationDbContext context)
		{
			context.Contacts.AddOrUpdate(p => p.Name,
				new Contacts { ContactId = 1, Name = "Ivan Irons", Address = "One Microsoft Way", City = "Redmond", State = "WA", Zip = "10999", Email = "ivani@wideworldimporters.com" },
				new Contacts { ContactId = 2, Name = "Brent Scholl", Address = "5678 1st Ave W", City = "Redmond", State = "WA", Zip = "10999", Email = "brents@wideworldimporters.com" },
				new Contacts { ContactId = 3, Name = "Terrell Bettis", Address = "9012 State St", City = "Redmond", State = "WA", Zip = "10999", Email = "terrellb@wideworldimporters.com" },
				new Contacts { ContactId = 4, Name = "Jo Cooper", Address = "3456 Maple St", City = "Redmond", State = "WA", Zip = "10999", Email = "joc@wideworldimporters.com" },
				new Contacts { ContactId = 5, Name = "Ines Burnett", Address = "7890 2nd Ave E", City = "Redmond", State = "WA", Zip = "10999", Email = "inesb@wideworldimporters.com" }
				);
		}
	}
}

Open in new window

-saige-
0
volkingAuthor Commented:
NO JOY with either suggested solution remember I'm a beginner, stumbling through a tutorial way over my head.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

it_saigeDeveloperCommented:
What are the errors you are receiving?  The posted solution (with the right dependencies) is properly formatted.

-saige-
0
volkingAuthor Commented:
Error	4	Type or namespace definition, or end-of-file expected	C:\Users\Owner\documents\visual studio 2013\Projects\ContactManager\ContactManager\Migrations\Configuration.cs	70	11	ContactManager
Error	5	Type or namespace definition, or end-of-file expected	C:\Users\Owner\documents\visual studio 2013\Projects\ContactManager\ContactManager\Migrations\Configuration.cs	71	1	ContactManager
Error	2	Invalid token '=' in class, struct, or interface member declaration	C:\Users\Owner\documents\visual studio 2013\Projects\ContactManager\ContactManager\Migrations\Configuration.cs	68	40	ContactManager
Error	3	Invalid token '=' in class, struct, or interface member declaration	C:\Users\Owner\documents\visual studio 2013\Projects\ContactManager\ContactManager\Migrations\Configuration.cs	69	24	ContactManager
Error	1	} expected	C:\Users\Owner\documents\visual studio 2013\Projects\ContactManager\ContactManager\Migrations\Configuration.cs	12	10	ContactManager

Open in new window

0
it_saigeDeveloperCommented:
Did you provide the entire Configuration.cs code above?

-saige-
0
volkingAuthor Commented:
To make sure I didn't miss something .. here's ctrl-A again
thanks for the help


namespace ContactManager.Migrations
{
    using ContactManager.Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<ContactManager.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            protected override void Seed(ContactManager.Models.ApplicationDbContext context)
{
    context.Contacts.AddOrUpdate(p => p.Name,
       new Contacts
       {
           ContactId = 1,
           Name = "Ivan Irons",
           Address = "One Microsoft Way",
           City = "Redmond",
           State = "WA",
           Zip = "10999",
           Email = "ivani@wideworldimporters.com",
       },
       new Contacts
        {
            ContactId = 2,
            Name = "Brent Scholl",
            Address = "5678 1st Ave W",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "brents@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 3,
            Name = "Terrell Bettis",
            Address = "9012 State St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "terrellb@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 4,
            Name = "Jo Cooper",
            Address = "3456 Maple St",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "joc@wideworldimporters.com",
        },
        new Contacts
        {
            ContactId = 5,
            Name = "Ines Burnett",
            Address = "7890 2nd Ave E",
            City = "Redmond",
            State = "WA",
            Zip = "10999",
            Email = "inesb@wideworldimporters.com",
        }
        );
}
            AutomaticMigrationsEnabled = false;
            ContextKey = "ContactManager.Models.ApplicationDbContext";
        }}}
}

Open in new window

0
käµfm³d 👽Commented:
I agree with the above statements:  You have ill-formatted and structured code. This is going to sound harsh, but it's not meant to be:

As a beginner, you should learn good formatting structure for your code. It is very difficult to see problems in code when the structure is out of whack. This goes for any programming language, not just C#. Follow the generally accepted formatting standards for C#, and you should ease much of your analysis of code issues.

That said, I believe the correct code is:

namespace ContactManager.Migrations
{
    using ContactManager.Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<ContactManager.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            ContextKey = "ContactManager.Models.ApplicationDbContext";
        }

        protected override void Seed(ContactManager.Models.ApplicationDbContext context)
        {
            context.Contacts.AddOrUpdate(p => p.Name,
               new Contacts
               {
                   ContactId = 1,
                   Name = "Ivan Irons",
                   Address = "One Microsoft Way",
                   City = "Redmond",
                   State = "WA",
                   Zip = "10999",
                   Email = "ivani@wideworldimporters.com",
               },
               new Contacts
                {
                    ContactId = 2,
                    Name = "Brent Scholl",
                    Address = "5678 1st Ave W",
                    City = "Redmond",
                    State = "WA",
                    Zip = "10999",
                    Email = "brents@wideworldimporters.com",
                },
                new Contacts
                {
                    ContactId = 3,
                    Name = "Terrell Bettis",
                    Address = "9012 State St",
                    City = "Redmond",
                    State = "WA",
                    Zip = "10999",
                    Email = "terrellb@wideworldimporters.com",
                },
                new Contacts
                {
                    ContactId = 4,
                    Name = "Jo Cooper",
                    Address = "3456 Maple St",
                    City = "Redmond",
                    State = "WA",
                    Zip = "10999",
                    Email = "joc@wideworldimporters.com",
                },
                new Contacts
                {
                    ContactId = 5,
                    Name = "Ines Burnett",
                    Address = "7890 2nd Ave E",
                    City = "Redmond",
                    State = "WA",
                    Zip = "10999",
                    Email = "inesb@wideworldimporters.com",
                }
                );
        }
    }
}

Open in new window


...which is essentially the same code that it_saige posted, just with all Contacts included. You have some brace issues in your original code (on top of the aforementioned constructor issue).
0
volkingAuthor Commented:
I've requested that this question be deleted for the following reason:

found answer elsewhere
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.