Consider the following code where Entity3 and Entity4 expose the same column name as different property names.
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
public abstract partial class Entity1 : Entity<int>
{
#region Fields
private int _discriminator;
#endregion
#region Field attribute and view names
/// <summary>Identifies the Discriminator entity attribute.</summary>
public const string DiscriminatorField = "Discriminator";
#endregion
#region Properties
[System.Diagnostics.DebuggerNonUserCode]
public int Discriminator
{
get { return Get(ref _discriminator, "Discriminator"); }
set { Set(ref _discriminator, value, "Discriminator"); }
}
#endregion
}
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
[Discriminator(Attribute="Discriminator", Value=1)]
public partial class Entity2 : Entity1
{
#region Fields
private string _entityProperty1;
private string _entityProperty2;
private bool _isActive;
#endregion
#region Field attribute and view names
/// <summary>Identifies the EntityProperty1 entity attribute.</summary>
public const string EntityProperty1Field = "EntityProperty1";
/// <summary>Identifies the EntityProperty2 entity attribute.</summary>
public const string EntityProperty2Field = "EntityProperty2";
/// <summary>Identifies the IsActive entity attribute.</summary>
public const string IsActiveField = "IsActive";
#endregion
#region Properties
[System.Diagnostics.DebuggerNonUserCode]
public string EntityProperty1
{
get { return Get(ref _entityProperty1, "EntityProperty1"); }
set { Set(ref _entityProperty1, value, "EntityProperty1"); }
}
[System.Diagnostics.DebuggerNonUserCode]
public string EntityProperty2
{
get { return Get(ref _entityProperty2, "EntityProperty2"); }
set { Set(ref _entityProperty2, value, "EntityProperty2"); }
}
[System.Diagnostics.DebuggerNonUserCode]
public bool IsActive
{
get { return Get(ref _isActive, "IsActive"); }
set { Set(ref _isActive, value, "IsActive"); }
}
#endregion
}
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
[Discriminator(Attribute="Discriminator", Value=2)]
public partial class Entity3 : Entity1
{
#region Fields
[Column("TokenSecret")]
[ValidateLength(0, 255)]
private string _password;
#endregion
#region Field attribute and view names
/// <summary>Identifies the Password entity attribute.</summary>
public const string PasswordField = "Password";
#endregion
#region Properties
[System.Diagnostics.DebuggerNonUserCode]
public string Password
{
get { return Get(ref _password, "Password"); }
set { Set(ref _password, value, "Password"); }
}
#endregion
}
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
[Discriminator(Attribute="Discriminator", Value=3)]
public partial class Entity4 : Entity1
{
#region Fields
[ValidateLength(0, 255)]
private string _tokenSecret;
[ValidateLength(0, 255)]
private string _token;
#endregion
#region Field attribute and view names
/// <summary>Identifies the TokenSecret entity attribute.</summary>
public const string TokenSecretField = "TokenSecret";
/// <summary>Identifies the Token entity attribute.</summary>
public const string TokenField = "Token";
#endregion
#region Properties
[System.Diagnostics.DebuggerNonUserCode]
public string TokenSecret
{
get { return Get(ref _tokenSecret, "TokenSecret"); }
set { Set(ref _tokenSecret, value, "TokenSecret"); }
}
[System.Diagnostics.DebuggerNonUserCode]
public string Token
{
get { return Get(ref _token, "Token"); }
set { Set(ref _token, value, "Token"); }
}
#endregion
}
LightSpeed successfully saves "Password" to the database, but when I query which Entity3 rows have a specific password, I get the following error:
Unable to materialize field [Password] on type [Entity3]. Check your table has an Id column and that your mappings are correct.
with an inner exception
Index was outside the bounds of the array.
Any ideas what this error is about? I'm making the assumption here that perhaps LightSpeed doesn't support this sort of thing and that I have to either move TokenSecret to the base class, or have the password property have its own column. That said, I'm not an advocate of the database design dictating how I name my classes or properties.
Thanks,
Werner