0
public class JobDescription
    {
        public int JobDescriptionID { get; set; }

        //          

        public virtual List<Image> Image { get; set; }

    }

 public class Image
    {
        public int ImageID { get; set; }

        [Required]
        public int JobDescriptionID { get; set; }

        [ForeignKey("JobDescriptionID")]
        public virtual JobDescription JobDescription { get; set; }

        public virtual List<ImageSection> ImageSection { get; set; }
    }

 public class ImageSection
    {
        public int ImageSectionID { get; set; }

        //
        public int ImageID { get; set; }

        [ForeignKey("ImageID")]
        public virtual Image Image { get; set; }

        public virtual DigitalSection DigitalSection { get; set; }

    }

public class DigitalSection
    {
        public int DigitalSectionID { get; set; }

         public int ImageSectionID { get; set; }

         [ForeignKey("ImageSectionID")]
         public virtual ImageSection ImageSection { get; set; }

         public virtual VerifiedSection VerifiedSection { get; set; }
    }

public class VerifiedSection
    {
        public int VerifiedSectionID { get; set; }


        public string DigitizedText { get; set; }


        public int DigitalSectionID { get; set; }

        [ForeignKey("DigitalSectionID")]
        public virtual DigitalSection DigitalSection { get; set; }

    }

我正在使用 CodeFirst 方法,并且我有JobDscriptionID. 现在我想DigitizedTextVerifiedSection表中删除所有内容。怎么做 ?

4

2 回答 2

1

试试这个 :

var result = contetx.VerifiedSection
            .Where(V => V.DigitalSection.ImageSection.Image.JobDescription.JobDescriptionID == 1)
            .Select(V => V.DigitizedText);

或者,您也可以使用 Join

var result = context.VerifiedSection.Join(context.DigitalSection.Join(
                    (context.ImageSection.Join
                    (context.Image.Join
                    (context.JobDescription.Where(J=> .JobDescriptionID == 1)), I=> I.JobDescriptionID, J => J.JobDescriptionID , (I,J) => I)
                    IS => IS.ImageID, I=> I.ImageID, (IS,I) => IS)
                    D => D.ImageSectionID, IS => IS.ImageSectionID , (D,IS) => D)
                    V => V.DigitalSectionID, D => D.DigitalSectionID, (V,D) => V.DigitizedText);

祝你好运 !!

于 2012-09-30T05:12:44.847 回答
0
var query = (from image in Context.Image 
            Where image.JobDescriptionID == id
            select image.ImageID).SingleOrDefault();

var query2 = (from select in Context.ImageSection 
            Where select.ImageID == query
            select select.ImageSectionID).SingleOrDefault();

var query3 = (from digital in Context.DigitalSection 
                Where digital.ImageSectionID == query2
                select digital.DigitalSectionID).SingleOrDefault();

var query4 = from text in Context.VerifiedSection 
            Where text.VerifiedSection == query3
            select select.DigitizedText;

Kundan Singh Chouhan 给了你一个更好的答案,但也许你想用“查询”的方式来做。

于 2012-09-30T07:48:09.273 回答