How to prevent linq-to-sql designer undo my changing
Posted
by anonim.developer
on Stack Overflow
See other posts from Stack Overflow
or by anonim.developer
Published on 2010-06-16T17:17:52Z
Indexed on
2010/06/16
17:22 UTC
Read the original article
Hit count: 313
linq-to-sql
Dear All,
Thanks for your attention in advance,
I’ve met an issue with LINQ-2-SQL designer in VS 2008 SP1 which has made me CRAZY. I use Linq2sql as my DAL. It seems Linq2sql speeds up coding in the first step but lots of issues arise in feature specifically with table or object inheritance.
In this case I have a class Entity
that all other entity classes generated by Linq2sql designer inherit from.
public abstract class Entity
{
public virtual Guid ID { get; protected set; }
}
public partial class User : monius.Data.Entity
{
}
And the following generated by L2S designer (DataModel.designer.cs
)
[Column(Storage = "_ID", AutoSync = AutoSync.OnInsert, DbType = "UniqueIdentifier NOT NULL",
IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
[DataMember(Order = 1)]
public System.Guid ID
{
get
{
return this._ID;
}
set
{
if ((this._ID != value))
{
this.OnIDChanging(value);
this.SendPropertyChanging();
this._ID = value;
this.SendPropertyChanged("ID");
this.OnIDChanged();
}
}
}
When I compile the code VS warns me that
Warning 1 'User.ID' hides inherited member 'Entity.ID'. To make the current member override that mplementation, add the override keyword. Otherwise add the new keyword.
That warning is obvious and I have to change the code generated by L2S designer (DataModel.designer.cs
) to
[…]
public override System.Guid ID
{
…
protected set
…
}
And the code compiled with no error or warning and everyone is happy. But that is not the end of story. As soon as I made changes to entities of the diagram (dbml) or even I open dbml file to view it, any change manually I made to designer has been vanished and POOF! Redo AGAIN. That is a painful job.
Now I wonder if there is a way to force L2S designer not changing portions of auto-generated code.
I’ll be appreciated if someone kindly helps me with this issue.
© Stack Overflow or respective owner