Ok, I am only a few days into using Linq and I am already getting annoyed. I have a need to create an abstract base class that will have a few common properties (columns) that will be used by all my inherited classes. Here is what I WAS wanting to do.
public abstract class StagedUserInformation
{
[Column( DbType = "Int" )]
public virtual Int32 UserID { get; set; }
[Column( DbType = "VarChar(10)" )]
public virtual string Pin { get; set; }
}
[Table( Name = "AccessKeyUserStagingForMyPI" )]
public class StagedUserInformationForMyPI : StagedUserInformation
{
// no logic yet
}
You will notice that my 2 columns in the base class have the column attribute, and the inherited class has my table attribute. This is exactly the way I want this to work. However, when you try to do this you get the following error:
System.InvalidOperationException: Data member 'Int32 UserID' of type 'AccessKey.Domain.Entities.StagedUserInformation' is not part of the mapping for type 'StagedUserInformationForMyPI'. Is the member above the root of an inheritance hierarchy?
In order to get around this, here is what I had to do.
public abstract class StagedUserInformation
{
public virtual Int32 UserID { get; set; }
public virtual string Pin { get; set; }
}
[Table( Name = "AccessKeyUserStagingForMyPI" )]
public class StagedUserInformationForMyPI : StagedUserInformation
{
[Column(DbType = "Int")]
public override Int32 UserID { get; set; }
[Column(DbType = "VarChar(10)")]
public override string Pin { get; set; }
}
Having done this, I realized that I do not need an abstract class, but could use an interface so I made the change.
[Table( Name = "AccessKeyUserStagingForMyPI" )]
public class StagedUserInformationForMyPI : IStagedUserInformation
{
[Column(DbType = "Int")]
public Int32 UserID { get; set; }
[Column(DbType = "VarChar(10)")]
public string Pin { get; set; }
}
I guess what bothers me most is this concept seems pretty simple, but it has not been implemented. And based on what I read (here) this was NOT implemented on purpose.
Till next time,
Posted
03-27-2008 7:36 AM
by
Derik Whittaker