Asp.net 在实体框架中读取相关数据

Asp.net 在实体框架中读取相关数据,asp.net,entity-framework,Asp.net,Entity Framework,我有两个名为StaticPages和StaticPagesContents的表,这两个表与StaticPages中的StaticSn和StaticPagesContents中的StaticID相关。 我需要从名为PageContent的StaticPagesContents中读取一个字段,并在我的一个控件上显示该数据,因此我使用以下代码: if (DropDownList1.SelectedIndex > -1) { using (shahedWSE

我有两个名为StaticPages和StaticPagesContents的表,这两个表与StaticPages中的StaticSn和StaticPagesContents中的StaticID相关。 我需要从名为PageContent的StaticPagesContents中读取一个字段,并在我的一个控件上显示该数据,因此我使用以下代码:

if (DropDownList1.SelectedIndex > -1)
        {
            using (shahedWSEntities myEntity = new shahedWSEntities())
            {
                var content = (from s in myEntity.StaticPages
                               where s.StaticSn == Convert.ToInt32(DropDownList1.SelectedValue)
                               select s);
                if (!object.ReferenceEquals(content, null))
                { 
                    CKEditorControl1.Text=...
                }
            }
        }
但我无法访问StaticPageContents的PageContent字段。你能帮帮我吗?

试试看

var content = (from contents in myEntity.StaticPagesContents
                join sp in myEntity.StaticPages
                on contents.StaticID equals sp.StaticSn 
                           where sp.StaticSn == Convert.ToInt32(DropDownList1.SelectedValue)
                           select contents);
我可能使用了错误的ID列,但我认为这将为您工作