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

  • SEARCH
  • Home
  • 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 4231186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:56:32+00:00 2026-05-21T01:56:32+00:00

What am i missing? City.cs [Table(Name = City)] public class City { [Column(IsDbGenerated =

  • 0

What am i missing?

City.cs


[Table(Name = "City")]
    public class City
    {
        [Column(IsDbGenerated = true, IsPrimaryKey = true)]
        public int CityId { get; set; }

        [Column(CanBeNull = false)]
        public string CityName { get; set; }


        private EntitySet<CityLocality> _cityLocalities;

        [Association(Storage = "_CityLocality", OtherKey = "CityId", Name = "City_CityLocality")]
        public EntitySet<CityLocality> CitiyLocalities
        {
            get { return _cityLocalities; }
            set { _cityLocalities.Assign(value);}
        }

CityLocality

  [Table(Name = "CityLocality")]
    public class CityLocality
    {
       [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int LocalityId { get; set; }

        [Column(CanBeNull = false)]
        public string LocalityName { get; set; }

        [Association(Name = "FK_CityLocation_City", Storage = "_City", ThisKey = "CityId", OtherKey = "CityId", IsForeignKey = true)]
        [Column(CanBeNull = false)]
        public int CityId { get; set; }


    }

SqlCityRepository


 public class SqlCityRepository : ICityRepository
    {
        private Table<City> _citys;

        public SqlCityRepository(string connectionString)
        {
            _citys = (new DataContext(connectionString)).GetTable<City>();

        }

        public IQueryable<City> Cities
        {
            get { return _citys; }
        }

        public void Add(City city)
        {
            if(city.CityId == 0)
            {
                _citys.InsertOnSubmit(city);
            }
            else
            {
                _citys.Attach(city);
                _citys.Context.Refresh(RefreshMode.KeepCurrentValues,city);
            }
            _citys.Context.SubmitChanges();
        }

        public City GetById(int cityId)
        {
            return (from c in _citys where c.CityId == cityId select c).FirstOrDefault();
        }
    }

TestFixture


   [Test]
        public void CityAddFunctionalityShouldWork()
        {
            var repository = new SqlCityRepository(_connectionSting);
            var city = new City();
            city.CityName = "BagChenDil";


            using(var scope = new TransactionScope())
            {
                repository.Add(city);
                var banChenDil = (from c in repository.Cities select c).FirstOrDefault();

                Assert.AreEqual(banChenDil.CityName, city.CityName);

                scope.Dispose();
            }

        }

Error Message:

System.InvalidOperationException: Bad Storage property: ‘_CityLocality’ on member ‘Entities.Location.City.CitiyLocalities’.

  • 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-21T01:56:33+00:00Added an answer on May 21, 2026 at 1:56 am

    There were couple of issues with this.

    1) notice.

    private EntitySet<CityLocality> _cityLocalities;
    

    This should have been.

    private EntitySet<CityLocality> _cityLocalities = new EntitySet<CityLocality>();
    

    2) [Association(Storage = "_CityLocality",
    this should have been.

       [Association(Storage = "_cityLocalities",
    

    3) Checked the DB Schema and found that had the columns as nullable just in case i changed them from nullable to not nullable.

    and things worked fine.

    Kind Regards
    Vinay.

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

Sidebar

Related Questions

Am I missing something? There is this: public boolean onTouchEvent (MotionEvent event) I use
I seem to be missing something about LINQ. To me, it looks like it's
I'm missing something here: $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry $objSearcher.Filter =
What is missing in the Visual Studio 2008 Express Editions? In particular, what functionality
I might be missing something really obvious. I'm trying to write a custom Panel
in CSS: The missing manual the author says that font-size: medium (or other size
I might be missing something obvious but is there a reference somewhere about what
Unless I am missing an obvious built-in method, what is the quickest way to
I'm probably missing something very obvious here. I have files with the extension .st
No doubt I'm missing something really simple here but I just can't see the

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.