I have Linq to SQL classes which I have extended with partial classes. Specifically I made a base class which a few classes (SQL tables) inherit.
public abstract class DeviceTable
{
public long ID { get; set; }
}
partial public class Blade : DeviceTable { }
Here is the auto-generated ID property in the ORM for class Blade
[Global.System.Data.Linq.Mapping.ColumnAttribute(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public long ID {
get {
return this._ID;
}
set {
if (((this._ID == value)
== false)) {
this.OnIDChanging(value);
this.SendPropertyChanging;
this._ID = value;
this.SendPropertyChanged("ID");
this.OnIDChanged;
}
}
}
It allows me to add some polymorphism to some similar tables. However there is a compiler warning
'Blade.ID' hides inherited member 'DeviceTable.ID'. Use the new keywoard if hiding was intended.
I would like to suppress this warning but if I add to the auto-generated file
#pragma warning disable CS0108
it suppresses the warning until the file is regenerated. Is there a way to add it more permanently?
Adding an example of how the base class is used
var tableName = testType.TableDUT;
var ty = Type.GetType(String.Format("CompanyName.Utilities.{0}, Utilities", tableName));
var q = string.Format("select ID, Name from {0} where Name = '{1}'", tableName, fullSerialNumber);
dynamic res;
switch (tableName)
{
case "Diode":
res = Support.getDevice((IEnumerable<DeviceTable>)dc.ExecuteQuery<CompanyName.Utilities.Linq.Diode>(q).ToList(), ty);
if (res.ID == 0) dc.Diodes.InsertOnSubmit((CompanyName.Utilities.Linq.Diode)res);
break;
case "Blade":
res = Support.getDevice((IEnumerable<DeviceTable>)dc.ExecuteQuery<CompanyName.Utilities.Linq.Blade>(q).ToList(), ty);
if (res.ID == 0) dc.Blades.InsertOnSubmit((CompanyName.Utilities.Linq.Blade)res);
break;
case "Engine":
res = Support.getDevice((IEnumerable<DeviceTable>)dc.ExecuteQuery<CompanyName.Utilities.Linq.Engine>(q).ToList(), ty);
if (res.ID == 0) dc.Engines.InsertOnSubmit((CompanyName.Utilities.Linq.Engine)res);
break;
case "Optic":
res = Support.getDevice((IEnumerable<DeviceTable>)dc.ExecuteQuery<CompanyName.Utilities.Linq.Optic>(q).ToList(), ty);
if (res.ID == 0) dc.Optics.InsertOnSubmit((CompanyName.Utilities.Linq.Optic)res);
break;
case "Mechanical":
res = Support.getDevice((IEnumerable<DeviceTable>)dc.ExecuteQuery<CompanyName.Utilities.Linq.Mechanical>(q).ToList(), ty);
if (res.ID == 0) dc.Mechanicals.InsertOnSubmit((CompanyName.Utilities.Linq.Mechanical)res);
break;
default:
res = null;
break;
}
if (res.ID == 0)
{
res.Name = fullSerialNumber;
res.Rev = rev;
dc.SubmitChanges();
}
getDevice method
public static T getDevice<T>(IEnumerable<T> devices, Type type) where T : DeviceTable
{
if (devices.Count() >= 1)
{
return devices.First();
}
else if (devices.Count() == 0)
{
var instance = Activator.CreateInstance(type);
return (T)(DeviceTable)instance;
}
else return null;
}