“Bad storage property” error in Linq to SQL
April 30, 2009 | In Development | No CommentsI had a problem when using the LINQ data mapping in my object. I received the error
Bad Storage property: '_id' on member ...
A quick search on Google failed to provide a proper answer, this article was the only really relevant one I found. This suggests making the member variable protected, which is essentially a bodge and not a solution.
It turns out the answer was that my member variable was public, as well as my property, thus changing the member variable to private meant it worked. I’m not sure why this is the answer, but it is correct code in this situation, which is the important thing. I wonder if they cannot both have the same accessiblity modifier….?
The class therefore reads:
private Guid _id = Guid.Empty;
[Column(Name = "Id", Storage = "_id", DbType = "uniqueidentifier not null", IsPrimaryKey = true, IsDbGenerated = true)]
public Guid Id { get { return _id; } set { _id = value; }