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; }

    }

I am using CodeFirst approach and I have JobDscriptionID. Now i want to retireve all the DigitizedText from VerifiedSection Table. How to do it ?

2
  • If you need DigitizedText from VerifiedSection table than its just like getting a column value from table. And its not getting data with multiple tables. Commented Sep 30, 2012 at 4:51
  • I don't want all the DigitizedText rather Just those linked provided ID. Commented Sep 30, 2012 at 4:56

2 Answers 2

1

Try this :

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

Alternately you could also use 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);

Good Luck !!

Sign up to request clarification or add additional context in comments.

Comments

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 gave you a better answer, but perhaps you'd like to do it the "Queries" way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.