0

I am very new to translating queries to entity, I don't know how to replace that query into linq in my code

select 
    brules.rule_description, brules.user_story_number, 
    so.source_name, 
    count(dlog.row_id) as error_count, 
    cast(execution_date as date) as execution_date
from 
    br.lk_business_rules brules
inner join 
    br.business_rules_detailed_log dlog on dlog.user_story_number = brules.user_story_number
inner join 
    br.lk_business_rules_source so on so.source_id = source_id_fk
where 
    brules.status_id_fk = 3
group by 
    brules.rule_description, brules.user_story_number,
    so.source_name, cast(execution_date as date)
order by 
    brules.rule_description

i tried this:

        var query = from br in _context.Lk_business_rules
                    join detLog in _context.Business_rules_detailed_log
                    on br.User_story_number equals detLog.User_story_number
                    join source in _context.Lk_business_rules_source
                    on detLog.Source_id equals source.Source_id
                    where br.Status_id_fk == 3
                    select new
                    {
                        Business_rule_description = br.Rule_description,
                        Business_rule_storynumber = br.User_story_number,
                        Source = source.Source_name,
                        Error_count = detLog.Row_id.Count,
                        Date = detLog.Execution_date
                    };

but not succed

  • 1
    Fun. Have you tried anything? If you run into a specific problem, you can ask a question here. – jarlh Sep 08 '20 at 20:44
  • Your issue isn't a join issue, it is a group by issue. Have a look at the documentation and examples on SO like: https://stackoverflow.com/questions/11564311/sql-to-entity-framework-count-group-by – Steve Py Sep 08 '20 at 21:48
  • Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you. – NetMage Sep 08 '20 at 23:13
  • wow, that helps a lot, I'll dive into these answers to see if any can help me, thanks guys! – BelgratoSystem Sep 09 '20 at 00:28

0 Answers0