views:

370

answers:

3
A: 
from question in db.Survey_Questions
    let surveys = (from s in db.Surveys 
     where string.Equals(s.Type, type, StringComparison.InvariantCultureIgnoreCase) &&
     s.Type_ID == typeID)
where surveys.Any() && 
surveys.Contains(s => s.ID == question.ID)
select new Mapper.Question
{
    ID = question.Id,
    Name = question.Name,
    Text = question.Text,
    Choices = ToBusinessObject(question.Question_Choices.ToList()),
    Status = question.Status
}

Does that get you on the right track?

Gabriel Isenberg
A: 

Why are you duplicating all your classes? You could just extend the LINQ to SQL classes with your business logic - they are partial classes. This is somewhat against the purpose of an OR mapper - persisting business entities.

Daniel Brückner
+1  A: 

What I needed to do was setup a join.

  public List<Model.Question> GetSurveyQuestions(string type, int typeID)
    {
        using (eMTADataContext db = DataContextFactory.CreateContext())
        {
            return db.Survey_Questions
                     .Where(s => s.Survey.Type.Equals(type) && s.Survey.Type_ID.Equals(typeID))
                     .Join(db.Questions,
                              sq => sq.Question_ID,
                              q => q.ID,
                              (sq, q) => Mapper.ToBusinessObject(q, sq.Status)).ToList();
        }
    }

And then overload my Mapper Function

  internal static Model.Question ToBusinessObject(Linq.Question q, string status)
    {
        return new Model.Question
        {
            ID = q.ID,
            Name = q.Name,
            Text = q.Text,
            Status = status,
            Choices = ToBusinessObject(q.Question_Choices.ToList()),
        };
    }
TonyAbell