0

Can you please let me know why I am not able to add data to Region table here?

protected void Button4_Click(object sender, EventArgs e)
{
    Region newRegion = new Region()
    {
        RegionID = 5000,
        RegionDescription = TextBox1.Text

    };

    db.Regions.Add(newRegion);
    db.SaveChanges();
}

I am getting this error:

enter image description here

at:

db.Regions.Add(newRegion);

I have a Region class as:

namespace EFDataStore
{
    using System;
    using System.Collections.Generic;

    public partial class Region
    {
        public int RegionID { get; set; }
        public string RegionDescription { get; set; }
    }
}

1 Answer 1

2

It seems that you have namespace conflict. You will need full namespace for Region class.

protected void Button4_Click(object sender, EventArgs e)
{
    var newRegion = new EFDataStore.Region() <==== Need full namespace.
    {
        RegionID = 5000,
        RegionDescription = TextBox1.Text

    };

    db.Regions.Add(newRegion);
    db.SaveChanges();

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.