Click here to Skip to main content
16,004,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
IQueryable<employee> emp = (from x in db.GetTable<employee>()
                                    join y in db.employesalaries on new (x.Id,Datetime.now.Month) equals (y.employe_id,y.paymentdate.Mont) into ps
                                    from salary in ps.DefaultIfEmpty();
                                    where x.branch_id == branchId && salary.payment_date.Month != DateTime.Now.Month
                                    select x);

I want to get all employees unpaid payment of current month .and also if its his first payment then defiantly record will not be in db.emloyesalaries . please help me out how can i use this with the help of linq.

What I have tried:

in this query . i always get records even when i pay the bill of current month . also if id is not in db.employesalaries .i can see employee .
Posted
Updated 6-Oct-16 3:32am

1 solution

You need to to check if record in emplyeesalaries table month is smaller than previous month which can be checked like:

C#
int currentMonth = Datetime.Now.Month;
int previousMonth = Datetime.Now.AddMonths(-1).Month;
IQueryable<employee> emp = (from x in db.GetTable<employee>()
                            join y in db.employesalaries 
                            on new {x.Id,currentMonth} 
                            equals new {y.employe_id,y.paymentdate.Month} into ps
                            from salary in ps.DefaultIfEmpty();
                            // for first salary and current month salary not deposited
                            where salary ==null 
                            && x.branch_id == branchId 
                            select x);
 
Share this answer
 
v9
Comments
Maciej Los 6-Oct-16 15:12pm    
Looks promising!
A5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900