using Microsoft Sql Server SMO to get relations in both direction -
how can query table related tables in both direction using smo
for example
table employee ..... jobid int null -- fk table job jobid int not null -- pk
using kind of generating tool ms t4 template, , smo; want reach following classes
class employee { ...... public int? job_id { { return _job_id; } set { if (_job_id!= value) { if (job != null && job.jobid != value) //the problem here (i cannot related pk related table) { job = null; } _job_id= value; } } } private int? _job_id; job thejob {get; set;} } class job { ..... icollection<employee> employees { ..... } }
here how related tables
public arraylist getchildren(table tbl, server server) { var result = new arraylist(); dependencywalker w = new dependencywalker(server); dependencytree tree = w.discoverdependencies(new sqlsmoobject[]{tbl}, dependencytype.children); dependencycollection depends = w.walkdependencies(tree); foreach (dependencycollectionnode dcn in depends) { //system.windows.forms.messagebox.show( tbl.name + " -> " + dcn.urn.parent); if (dcn.urn.type == "table" && dcn.urn.getnamefortype("table") != tbl.name) { result.add(dcn.urn.getnamefortype("table")); } } return result; }
but how can referenced primary key in related table (the pk related table i've fk for).
Comments
Post a Comment