Note that there are some explanatory texts on larger screens.

plurals
  1. POPOCO LinqToSQL ERROR: System.InvalidOperationException: Bad Storage property:
    text
    copied!<p>What am i missing? </p> <p>City.cs</p> <hr> <pre><code>[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&lt;CityLocality&gt; _cityLocalities; [Association(Storage = "_CityLocality", OtherKey = "CityId", Name = "City_CityLocality")] public EntitySet&lt;CityLocality&gt; CitiyLocalities { get { return _cityLocalities; } set { _cityLocalities.Assign(value);} } </code></pre> <hr> <p>CityLocality</p> <pre><code> [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; } } </code></pre> <hr> <p>SqlCityRepository</p> <hr> <pre><code> public class SqlCityRepository : ICityRepository { private Table&lt;City&gt; _citys; public SqlCityRepository(string connectionString) { _citys = (new DataContext(connectionString)).GetTable&lt;City&gt;(); } public IQueryable&lt;City&gt; 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(); } } </code></pre> <hr> <p>TestFixture</p> <hr> <pre><code> [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(); } } </code></pre> <p>Error Message:</p> <p><strong>System.InvalidOperationException: Bad Storage property: '_CityLocality' on member 'Entities.Location.City.CitiyLocalities'.</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload