Pavel Minaev said:
I'm not so sure where to go from here now... are you sure you have set
up the inheritance correctly in your LINQ to SQL mapping? Aside from
that, I can't really think of anything. Maybe if you provide your
table definition for the hierarchy, and the mapping, it would be
possible to repro that and see what's wrong.
Here the code for translating SQL data to domain classes:
IQueryable<DomainModel.Profile> result =
from p in DC.Profiles
select
p.ProfileTyp == (ushort)DomainModel.ProfileType.Rund ?
new DomainModel.ProfileCircular
{
// if next statement is missing
// exception "has no supported translation to SQL"
// would be raised when using ProfileTyp as parameter
// in expression tree for dynamic filtering
ProfileTyp = (DomainModel.ProfileType)p.ProfileTyp,
ID = p.ID,
Name = p.Name,
Diameter = (p as CircularProfile).Diameter,
Comment = p.Comment,
modified = p.modified,
Version = p.Version
} :
p.ProfileTyp == (ushort)DomainModel.ProfileType.Rechteck ?
new DomainModel.ProfileRectangle
{
ProfileTyp = (DomainModel.ProfileType)p.ProfileTyp,
ID = p.ID,
Name = p.Name,
Size_X = (p as RectangleProfile).Size_X,
Size_Y = (p as RectangleProfile).Size_Y,
EdgeRadius = (p as RectangleProfile).EdgeRadius,
Comment = p.Comment,
modified = p.modified,
Version = p.Version
} :
p.ProfileTyp == (ushort)DomainModel.ProfileType.Sonder ?
new DomainModel.ProfileArbitrary
{
ProfileTyp = (DomainModel.ProfileType)p.ProfileTyp,
ID = p.ID,
Name = p.Name,
Size_X = (p as ArbitraryProfile).Size_X,
Size_Y = (p as ArbitraryProfile).Size_Y,
CenterOfArea_X = (p as ArbitraryProfile).CenterOfArea_X,
CenterOfArea_Y = (p as ArbitraryProfile).CenterOfArea_Y,
Drawing = (p as ArbitraryProfile).Drawing,
Comment = p.Comment,
modified = p.modified,
Version = p.Version
} :
new DomainModel.Profile();
return result;
Here the mapping definition:
[Table(Name = "Profiles")]
[InheritanceMapping(Code = "0", Type = typeof(CircularProfile), IsDefault =
true)]
[InheritanceMapping(Code = "1", Type = typeof(RectangleProfile))]
[InheritanceMapping(Code = "10", Type = typeof(ArbitraryProfile))]
public partial class Profile : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new
PropertyChangingEventArgs(String.Empty);
private int _ProfileID;
private ushort _ProfileTyp;
private string _Name;
private string _Comment;
private System.Nullable<System.DateTime> _modified;
private System.Data.Linq.Binary _Stamp;
private EntitySet<Pipe> _Pipes;
private EntitySet<BendTool> _Tools;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIDChanging(int value);
partial void OnIDChanged();
partial void OnProfileTypChanging(ushort value);
partial void OnProfileTypChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
partial void OnCommentChanging(string value);
partial void OnCommentChanged();
partial void OnmodifiedChanging(System.Nullable<System.DateTime> value);
partial void OnmodifiedChanged();
partial void OnVersionChanging(System.Data.Linq.Binary value);
partial void OnVersionChanged();
#endregion
public Profile()
{
this._Pipes = new EntitySet<Pipe>(new Action<Pipe>(this.attach_Pipes),
new Action<Pipe>(this.detach_Pipes));
this._Tools = new EntitySet<BendTool>(new
Action<BendTool>(this.attach_Tools), new Action<BendTool>(this.detach_Tools));
OnCreated();
}
[Column(Storage = "_ProfileID", AutoSync = AutoSync.OnInsert, DbType =
"Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int ID
{
get
{
return this._ProfileID;
}
set
{
if ((this._ProfileID != value))
{
this.OnIDChanging(value);
this.SendPropertyChanging();
this._ProfileID = value;
this.SendPropertyChanged("ID");
this.OnIDChanged();
}
}
}
[Column(Storage = "_ProfileTyp", IsDiscriminator = true)]
public ushort ProfileTyp
{
get
{
return this._ProfileTyp;
}
set
{
if ((this._ProfileTyp != value))
{
this.OnProfileTypChanging(value);
this.SendPropertyChanging();
this._ProfileTyp = value;
this.SendPropertyChanged("ProfileTyp");
this.OnProfileTypChanged();
}
}
}
[Column(Storage = "_Name", DbType = "NVarChar(50)", CanBeNull = false)]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[Column(Storage = "_Comment", DbType = "NVarChar(300)")]
public string Comment
{
get
{
return this._Comment;
}
set
{
if ((this._Comment != value))
{
this.OnCommentChanging(value);
this.SendPropertyChanging();
this._Comment = value;
this.SendPropertyChanged("Comment");
this.OnCommentChanged();
}
}
}
[Column(Storage = "_modified", DbType = "DateTime", UpdateCheck =
UpdateCheck.Never)]
public System.Nullable<System.DateTime> modified
{
get
{
return this._modified;
}
set
{
if ((this._modified != value))
{
this.OnmodifiedChanging(value);
this.SendPropertyChanging();
this._modified = value;
this.SendPropertyChanged("modified");
this.OnmodifiedChanged();
}
}
}
[Column(Storage = "_Stamp", AutoSync = AutoSync.Always, DbType =
"TIMESTAMP", CanBeNull = false, IsDbGenerated = true, IsVersion = true)]
public System.Data.Linq.Binary Version
{
get
{
return this._Stamp;
}
set
{
if ((this._Stamp != value))
{
this.OnVersionChanging(value);
this.SendPropertyChanging();
this._Stamp = value;
this.SendPropertyChanged("Version");
this.OnVersionChanged();
}
}
}
[Association(Name = "Profile_Pipe", Storage = "_Pipes", ThisKey = "ID",
OtherKey = "ProfileID")]
public EntitySet<Pipe> Pipes
{
get
{
return this._Pipes;
}
set
{
this._Pipes.Assign(value);
}
}
[Association(Name = "Profile_BendTool", Storage = "_Tools", ThisKey =
"ID", OtherKey = "ProfileID")]
public EntitySet<BendTool> Tools
{
get
{
return this._Tools;
}
set
{
this._Tools.Assign(value);
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void attach_Pipes(Pipe entity)
{
this.SendPropertyChanging();
entity.Profile = this;
}
private void detach_Pipes(Pipe entity)
{
this.SendPropertyChanging();
entity.Profile = null;
}
private void attach_Tools(BendTool entity)
{
this.SendPropertyChanging();
entity.Profile = this;
}
private void detach_Tools(BendTool entity)
{
this.SendPropertyChanging();
entity.Profile = null;
}
}
public partial class CircularProfile : Profile
{
private System.Nullable<float> _Diameter;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnDiameterChanging(System.Nullable<float> value);
partial void OnDiameterChanged();
#endregion
public CircularProfile()
{
OnCreated();
}
[Column(Storage = "_Diameter")]
public System.Nullable<float> Diameter
{
get
{
return this._Diameter;
}
set
{
if ((this._Diameter != value))
{
this.OnDiameterChanging(value);
this.SendPropertyChanging();
this._Diameter = value;
this.SendPropertyChanged("Diameter");
this.OnDiameterChanged();
}
}
}
}
public partial class NonCircularProfile : Profile
{
private System.Nullable<float> _Size_X;
private System.Nullable<float> _Size_Y;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnSize_XChanging(System.Nullable<float> value);
partial void OnSize_XChanged();
partial void OnSize_YChanging(System.Nullable<float> value);
partial void OnSize_YChanged();
#endregion
public NonCircularProfile()
{
OnCreated();
}
[Column(Storage = "_Size_X")]
public System.Nullable<float> Size_X
{
get
{
return this._Size_X;
}
set
{
if ((this._Size_X != value))
{
this.OnSize_XChanging(value);
this.SendPropertyChanging();
this._Size_X = value;
this.SendPropertyChanged("Size_X");
this.OnSize_XChanged();
}
}
}
[Column(Storage = "_Size_Y")]
public System.Nullable<float> Size_Y
{
get
{
return this._Size_Y;
}
set
{
if ((this._Size_Y != value))
{
this.OnSize_YChanging(value);
this.SendPropertyChanging();
this._Size_Y = value;
this.SendPropertyChanged("Size_Y");
this.OnSize_YChanged();
}
}
}
}
public partial class RectangleProfile : NonCircularProfile
{
private System.Nullable<float> _EdgeRadius;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnEdgeRadiusChanging(System.Nullable<float> value);
partial void OnEdgeRadiusChanged();
#endregion
public RectangleProfile()
{
OnCreated();
}
[Column(Storage = "_EdgeRadius")]
public System.Nullable<float> EdgeRadius
{
get
{
return this._EdgeRadius;
}
set
{
if ((this._EdgeRadius != value))
{
this.OnEdgeRadiusChanging(value);
this.SendPropertyChanging();
this._EdgeRadius = value;
this.SendPropertyChanged("EdgeRadius");
this.OnEdgeRadiusChanged();
}
}
}
}
public partial class ArbitraryProfile : NonCircularProfile
{
private System.Nullable<float> _CenterOfArea_X;
private System.Nullable<float> _CenterOfArea_Y;
private System.Data.Linq.Binary _Drawing;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnCenterOfArea_XChanging(System.Nullable<float> value);
partial void OnCenterOfArea_XChanged();
partial void OnCenterOfArea_YChanging(System.Nullable<float> value);
partial void OnCenterOfArea_YChanged();
partial void OnDrawingChanging(System.Data.Linq.Binary value);
partial void OnDrawingChanged();
#endregion
public ArbitraryProfile()
{
OnCreated();
}
[Column(Storage = "_CenterOfArea_X")]
public System.Nullable<float> CenterOfArea_X
{
get
{
return this._CenterOfArea_X;
}
set
{
if ((this._CenterOfArea_X != value))
{
this.OnCenterOfArea_XChanging(value);
this.SendPropertyChanging();
this._CenterOfArea_X = value;
this.SendPropertyChanged("CenterOfArea_X");
this.OnCenterOfArea_XChanged();
}
}
}
[Column(Storage = "_CenterOfArea_Y")]
public System.Nullable<float> CenterOfArea_Y
{
get
{
return this._CenterOfArea_Y;
}
set
{
if ((this._CenterOfArea_Y != value))
{
this.OnCenterOfArea_YChanging(value);
this.SendPropertyChanging();
this._CenterOfArea_Y = value;
this.SendPropertyChanged("CenterOfArea_Y");
this.OnCenterOfArea_YChanged();
}
}
}
[Column(Storage = "_Drawing", DbType = "VARBINARY(320)")]
public System.Data.Linq.Binary Drawing
{
get
{
return this._Drawing;
}
set
{
if ((this._Drawing != value))
{
this.OnDrawingChanging(value);
this.SendPropertyChanging();
this._Drawing = value;
this.SendPropertyChanged("Drawing");
this.OnDrawingChanged();
}
}
}
}