locked
Linq query clarification RRS feed

  • Question

  • Hi,

    can anyone please help me in getting the below value.

     var terHrtbtInfo = (from terHrtbt in dc.terminal_heartbeats
                                            where ((DateTime.Now - terHrtbt.rm_term_server_lastpingtime).TotalSeconds > chkTSDownInSecs)
                                            select new DTO.TerminalHeartbeatDTO
                                            {
                                                HostId = terHrtbt.rm_host_id,
                                                HostIp = terHrtbt.rm_host_ip,
                                                TerminalId = terHrtbt.rm_term_server_id,
                                                LastPingTime = terHrtbt.rm_term_server_lastpingtime,
                                                HostName = (from ts in dc.terminal_servers where ts.rm_host_id == terHrtbt.rm_host_id select ts.rm_term_server_name)
                                            }).ToList();
    I am unable to get the host name from terminal_servers table based on rm_host_id value, can anyone please correct my query.

    Tuesday, September 9, 2014 11:56 AM

Answers

  • Hello ykbharat,

    >>I am unable to get the host name from terminal_servers table based on rm_host_id value,

    I am not quite sure about this.

    Do you mean there is an error occurs? If it is, please share it with us.

    Or you mean that the query is executed successfully, however, the HostName property is null. If you are under this scenario, please check your data in database to see if there are correspondent records in terminal_servers table, because your query seems to be correct, since I do not know your detail table schema, I make a query similar with

    yours and it worked as expected:
    
    using (DFDBEntities db = new DFDBEntities())
    
                {
    
                    var result = (from order in db.Orders
    
                                  select new OOD { ID = order.OrderID, ODs = (from od in db.OrderDetails where od.OrderID == order.OrderID select od.OrderDetailID).ToList() }).ToList();
    
                }
    

    The result:

    If this does not work for you, please let me know.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by ykbharat Wednesday, September 10, 2014 4:07 AM
    Wednesday, September 10, 2014 2:37 AM