Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Pull FK Data
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
How To Pull FK Data
Divers
Thread ID:
01508206
Message ID:
01508206
Vues:
97
I have the following method in my data layer:
public static ProjectModel GetProject(int ProjectId)
{
    ProjectModel retVal = null;

    using (SparesDataContext dc = getDataContext())
    {
        retVal = (from p in dc.tblProjects
                    where p.ProjectId == ProjectId
                    select new ProjectModel
                    {
                        ProjectId = p.ProjectId,
                        UserId = p.UserId,
                        PrimaryWhseId = p.PrimaryWhseId,
                        SecondaryWhseId = p.SecondaryWhseId.Value,
                        ProjectType = getProjectTypeEnum(p.ProjectType.Value),
                        CustomerCode = p.CustomerCode,
                        CustomerName = p.CustomerName,
                        ProjectName = p.ProjectName,
                        ProjectNum = p.ProjectNum,
                        Date = p.Date,
                        Comments = p.Comments
                    }
                    ).FirstOrDefault();
    }

    return retVal;
}
and here's the ProjectModel:
    public class ProjectModel : _BaseModel
    {
        public int ProjectId { get; set; }
        public int UserId { get; set; }
        public WarehouseModel PrimaryWarehouse { get; set; }
        public WarehouseModel SecondaryWarehouse { get; set; }
        public ProjectType ProjectType { get; set; }
        public string CustomerCode { get; set; }
        public string CustomerName { get; set; }
        public string ProjectName { get; set; }
        public string ProjectNum { get; set; }
        public DateTime Date { get; set; }
        public string Comments { get; set; }
    }
Is it possible in this Linq query to pull the data from the Wharehouse table and populate the PrimaryWarehouse and SecondaryWarehouse properties with instances of those models inside this query?

I'm sure it's possible, but I dobn't know the syntax.

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform