public List <Dependency> selectByDependencyElementID(String id) { List <Dependency> result = null; using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = "Server=127.0.0.1;Port=5432;Database=nasca;Encoding=UTF-8;User Id=postgres;Password=nomura;"; connection.Open(); //string sql = // " select" // + " concat(elm1.elmtid, '-', elm2.elmtid) id," // + " elm1.elmtid," // + " elm1.elmtnm," // + " elm1.elmttp," // + " elm1.remark," // + " etp1.svgfle," // + " elm2.elmtid dpdelmtid," // + " elm2.elmtnm dpdelmtnm," // + " elm2.elmttp dpdelmttp," // + " elm2.remark dpdremark," // + " etp2.svgfle dpdsvgfle," // + " dpd.remark dpdrmk," // + " dpd.dpdtpc," // + " dpd.dpdtpr," // + " dpd.dpdtpu," // + " dpd.dpdtpd" // + " from" // + " t_depndncy dpd" // + " inner join m_element elm1 on" // + " dpd.elmtid = elm1.elmtid" // + " inner join m_element elm2 on" // + " dpd.dpdeid = elm2.elmtid" // + " left outer join m_elmttype etp1 on" // + " elm1.elmttp = etp1.elmttp" // + " left outer join m_elmttype etp2 on" // + " elm2.elmttp = etp2.elmttp" // + " where" // + " dpd.dpdeid = @id"; string sql = " select" + " concat(dpd.elmtid, '-', dpd.dpdeid) as id," + " dpd.remark as remark," + " dpd.dpdtpc as dependencyTypeCreate," + " dpd.dpdtpr as dependencyTypeRead," + " dpd.dpdtpu as dependencyTypeUpdate," + " dpd.dpdtpd as dependencyTypeDelete" + " from" + " t_depndncy dpd" + " where" + " dpd.dpdeid = @id"; result = connection.Query <Dependency>(sql, new { id = id }).ToList(); result.ForEach(dependency => { var ids = dependency.id.Split('-'); var elementDAO = new ElementDAO(); dependency.element = elementDAO.selectByID(ids[0]); dependency.dependencyElement = elementDAO.selectByID(ids[1]); }); } return(result); }