Replacement for MemberMapper and MemberMapperAttribute in LinqToDB #4423
-
I'm migrating from BLToolkit to LinqToDB. Unfortunatelly that code was not written by me and I've never been used BLToolkit before. [Table(Name = "Events")]
public sealed class Event:
{
[Column(CanBeNull = false, DbType = "uniqueidentifier", IsPrimaryKey = true)]
public new Guid Id { get; set; }
[Column]
public DateTime Date { get; set; }
[Column(DbType = "uniqueidentifier")]
[MemberMapper(typeof(GenericMemberMapper<IUser>))]
public IUser User{ get; set; }
}
public sealed class GenericMemberMapper<TProperty> : MemberMapper
{
public override object GetValue(object o)
{
return MyMappingSchema.Instance.ConvertParameterValue(base.GetValue(o), typeof(TProperty));
}
public override void SetValue(object o, object value)
{
base.SetValue(o, (TProperty)(MyMappingSchema.Instance.ConvertChangeType(value, typeof(TProperty))));
}
public override void Init(MapMemberInfo mapMemberInfo)
{
if (typeof(IEntity).IsAssignableFrom(typeof(TProperty)))
{
mapMemberInfo.DbType = DbType.Guid;
mapMemberInfo.IsDbTypeSet = true;
}
base.Init(mapMemberInfo);
}
} As I can see - there is no MemberMapper in LinqToDB. But if I comment
What is the replacement for MemberMapper and MemberMapperAttribute in LinqToDB? Is there some tutorial/docs section? I didn't find any migration guide, sorry. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This attribute tells BLToolkit how to convert database It can be replaced with |
Beta Was this translation helpful? Give feedback.
This attribute tells BLToolkit how to convert database
uniqueidentifier
column to yourIUser
object. There should be this logic somewhere in your code.It can be replaced with
MappingSchema SetConvertExpression/SetConverter
methods.