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 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

I have a table, jos_ezrealty that has address, city, state fields and declat &
<string name=no_city><font color='#FF0000'><b>Please select your location under Preferences in the menu</b></font> </string> @Override public
I have a json like: {156644:{ name:name1, street:street1, city:city1 68656:{ name:name2 , street:street2, city:city1
I have the following data structure: [DataServiceEntity] public class User { public string RowKey
I have a button like that : <a href=@Url.Action(Create, City) class=save button><span class=icon-save></span>Save</a> Than
In my sql server table, I want to add a computed column that is
I'm trying to get the latitude and longitude of a city with the Google
Given a couple of cities in the DB: City.first.attributes => {:id => 1, :name
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
I seem to be missing something about LINQ. To me, it looks like it's

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.