Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlTableDependencyFilter don't use Custom Mapping #50

Closed
wenner opened this issue Apr 23, 2018 · 1 comment
Closed

SqlTableDependencyFilter don't use Custom Mapping #50

wenner opened this issue Apr 23, 2018 · 1 comment
Assignees
Labels

Comments

@wenner
Copy link

wenner commented Apr 23, 2018

i have a column in database: "COM_TIME" and in model : "ComTime"

then use Custom Mapper

var mapper = new ModelToTableMapper<MyEvent>();
mapper.AddMapping(c => c.ComTime, "COM_TIME");

//Using SqlTableDependencyFilter
var dt = DateTime.Now;
Expression<Func<MyEvent, bool>> expression = p => p.ComTime == dt;
ITableDependencyFilter whereCondition = new SqlTableDependencyFilter<MyEvent>(expression);

it don't work ...

and i found error in sql profiler

CREATE TRIGGER [tr_dbo_SHIJIAN_e1647094-2b4a-44e6-9630-2ce4177d3f3d] ON [dbo].[SHIJIAN] AFTER update AS 
..........
 a WHERE ([ComTime] = '2018-04-24T03:55:47')
//there is ComTime and not COM_TIME ....
@christiandelbianco
Copy link
Collaborator

2018-04-24 at 15-38-17

2018-04-24 at 15-37-33

My test works without any issue:

            // Because our model has a property that does not match table column name, we need a mapper C# Model PROPERTY <--> Database Table Column Name
            var mapper = new ModelToTableMapper<Product>();
            mapper.AddMapping(c => c.ItemsInStock, "Quantity");
            mapper.AddMapping(c => c.ComTime, "COM_TIME");

            // Define WHERE filter specifing the WHERE condition
            // We also pass the mapper defined above as last contructor's parameter
            var ti = DateTime.Now;
            Expression<Func<Product, bool>> expression = p => (p.ComTime > ti);
            ITableDependencyFilter whereCondition = new SqlTableDependencyFilter<Product>(expression, mapper);

            // Create SqlTableDependency and pass filter condition, as weel as mapper
            using (var dep = new SqlTableDependency<Product>(connectionString, "Products", mapper: mapper, filter: whereCondition))
            {
                dep.OnChanged += Changed;
                dep.OnError += OnError;
                dep.Start();

                Console.WriteLine(@"TableDependency, SqlTableDependency, SqlTableDependencyFilter");
                Console.WriteLine(@"Copyright (c) 2015-2017 Christian Del Bianco.");
                Console.WriteLine(@"All rights reserved." + Environment.NewLine);
                Console.WriteLine();
                Console.WriteLine(@"Waiting for receiving notifications...");
                Console.WriteLine(@"Press a key to stop");
                Console.ReadKey();
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants