Dapper-FluentMap
Dapper-FluentMap copied to clipboard
Dommel doesn't handle ignored properties when inserting
When I mark a property with .Ignore() in the map, dommel doesn't handle this in the insert method, and there is an exception.
It should have a condition in the Linq expression that excludes ignored properties.
That's because Dommel does not implement the mapping defined in Dapper.FluentMap (yet). Dapper.FluentMap.Dommel should implement the query builder of Dommel and use the defined mapping to determine whether the property should be ignored.
So do you have an alternate solution if I want to ignore a property?
You could create your own implementation of ISqlBuilder
and use the mappings from Dapper.FluentMap to filter the column names added to the query.
https://github.com/henkmollema/Dommel/blob/master/src/Dommel/DommelMapper.cs#L2024 shows the default implementation of the SQL Server query builder.
Will this functionality be implemented? Lack of Ignore properties makes working with Dommel difficult.
I can not do this:
class Program
{
static void Main(string[] args)
{
FluentMapper.Initialize(config =>
{
config.AddMap(new PostMap());
config.ForDommel();
});
List<Poster> customers = new List<Poster>();
using (IDbConnection db = new SQLiteConnection("Data Source=D:\\test2.db;Version=3;"))
{
customers = db.GetAll<Poster>().ToList(); // there is an exception due to the inability to ignore
}
}
}
public class PostMap : DommelEntityMap<Poster>
{
public PostMap()
{
ToTable("tbl_messages");
Map(p => p.Index).ToColumn("id").IsKey().IsIdentity();
Map(p => p.Post).ToColumn("message");
Map(p => p.Creator).Ignore();
Map(p => p.CreatorValue).ToColumn("creator");
Map(p => p.TimeAdd).ToColumn("time_add");
Map(p => p.Flag).ToColumn("data_flag");
}
}
public class Poster
{
public int Index { get; set; } = -1;
public string Post { get; set; } = string.Empty;
public CreatorType Creator { get; set; } = CreatorType.User;
public string CreatorValue
{
get => Creator.ToString();
set => Creator = (CreatorType)Enum.Parse(typeof(CreatorType), value);
}
public DateTime TimeAdd { get; set; } = DateTime.Now;
public bool Flag { get; set; } = false;
}
I'm archiving this repository as I'm not using this library myself anymore and have no time maintaining it. Thanks for using it.