首页 新闻 搜索 专区 学院

Linq两表或多表关联查询方法?

0
悬赏园豆:20 [已关闭问题]

初学LINQ,我使用XmlMappingSource载入映射XML的方式

XML文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<Database Name="MyOA" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">
  <Table Name="dbo.My_Company">
    <Type Name="Entity.Company">
      <Column Name="ID" Member="ID" Storage="_ID" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true"/>
      <Column Name="Name" Member="Name" Storage="_Name" DbType="NVarChar(50) NOT NULL" CanBeNull="false" />
    </Type>
  </Table>
  <Table Name="dbo.My_Dept">
    <Type Name="Entity.Dept">
      <Column Name="ID" Member="ID" Storage="_ID" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true"/>
      <Column Name="ParentID" Member="ParentID" Storage="_ParentID" DbType="UniqueIdentifier NOT NULL" />
      <Column Name="Name" Member="Name" Storage="_Name" DbType="NVarChar(50) NOT NULL" CanBeNull="false" />
    </Type>
  </Table>

</Database>

代码文件Company.cs

using System;

namespace Entity
{
    [Serializable()]
    public class Company
    {
        private Guid _ID;
        public Guid ID
        {
            get { return _ID; }
            set
            {
                _ID = value;
            }
        }

        private string _Name;
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
            }
        }
       
    }
}

代码文件Dept.cs

using System;

namespace Entity
{
    [Serializable()]
    public class Dept
    {
        private Guid _ID;
        public Guid ID
        {
            get { return _ID; }
            set
            {
                _ID = value;
            }
        }

        private Guid _ParentID;
        public Guid ParentID
        {
            get { return _ParentID; }
            set
            {
                _ParentID = value;
            }
        }

        private string _Name;
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
            }
        }


    }
}

 

其中 My_Dept 表中的 ParentID 对应 My_Company 表中的 ID 字段

想在代码中查询My_Dept表时,同时能查到ParentID对应My_Company中的Name的值.请问XML文件和代码应该如何编写?

问题补充: 永京大虾,其实我的意思是: 代码文件Dept.cs using System; namespace Entity { [Serializable()] public class Dept { private Guid _ID; public Guid ID { get { return _ID; } set { _ID = value; } } //My_Company表中的ID private Guid _ParentID; public Guid ParentID { get { return _ParentID; } set { _ParentID = value; } } //My_Company表中的Name private string _CompanyName; public string CompanyName { get { return _CompanyName; } set { _CompanyName = value; } } private string _Name; public string Name { get { return _Name; } set { _Name = value; } } } } 能否在 DataContext.GetTable<Dept>();时 直接提取出对应的数据
颓废的主页 颓废 | 初学一级 | 园豆:150
提问于:2008-09-15 20:23
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册