Dapper-FluentMap icon indicating copy to clipboard operation
Dapper-FluentMap copied to clipboard

Dommel doesn't handle ignored properties when inserting

Open orenht opened this issue 7 years ago • 4 comments

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.

orenht avatar Jul 24 '17 08:07 orenht

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.

henkmollema avatar Jul 24 '17 08:07 henkmollema

So do you have an alternate solution if I want to ignore a property?

orenht avatar Jul 24 '17 11:07 orenht

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.

henkmollema avatar Jul 24 '17 11:07 henkmollema

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;
    }

gkurbesov avatar Jan 24 '20 21:01 gkurbesov

I'm archiving this repository as I'm not using this library myself anymore and have no time maintaining it. Thanks for using it.

henkmollema avatar Apr 19 '23 13:04 henkmollema