/// <summary> /// 存在于数据库中的数据集中 /// </summary> /// <param name="mdbPath">数据库路径</param> /// <param name="ORIFClassName">源要素类的名称</param> /// <param name="DESFClassName">目标要素类的名称</param> /// <param name="DatasetName">所在数据集的名称</param> /// <param name="newRSClassName">生成的关系类的名称</param> /// <param name="PrimaryKey">源表主键</param> /// <param name="ForeignKey">源表外键</param> /// <param name="isComposite">是否复合关系</param> public void createRelationShipClass(string mdbPath, string ORIFClassName, string DESFClassName, string DatasetName, string newRSClassName, string PrimaryKey, string ForeignKey, bool isComposite) { IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(mdbPath, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass pFeatureClassORI = pFeatureWorkspace.OpenFeatureClass(ORIFClassName); IFeatureClass pFeatureClassDES = pFeatureWorkspace.OpenFeatureClass(DESFClassName); IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(DatasetName); IRelationshipClassContainer pRSCContainer = pFeatureDataset as IRelationshipClassContainer; IRelationshipClass pRelationshipClass = pRSCContainer.CreateRelationshipClass( newRSClassName, //生成的关系类的名称 pFeatureClassORI, // 参与生成的源要素类/表 pFeatureClassDES, //参与生成的目标要素类/表 "", "", esriRelCardinality.esriRelCardinalityOneToMany, //表间关系 esriRelNotification.esriRelNotificationForward, //通知??? isComposite, //是否复合关系 false, //是否添加属性表 null, //字段集信息 PrimaryKey, //源表主键 "", ForeignKey, //源表外键 ""); } /*测试数据***** string mdbPath = "c:/Users/Administrator/Desktop/GXLTest.mdb"; string ORIFClassName="zd"; string DESFClassName="zrz"; string DatasetName="GXL"; string newRSClassName="relation1"; string PrimaryKey="zddm"; string ForeignKey = "zddm"; bool isComposite = true; createRelationShipClass(mdbPath,ORIFClassName,DESFClassName,DatasetName,newRSClassName,PrimaryKey,ForeignKey,isComposite); */
使用测试文件
提取密码:3td1
创建完成之后,在Arcmap中删除zd中的图块,则他所对应的zrz图块也随之删除