初学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文件和代码应该如何编写?