Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Pull FK Data
Message
 
To
23/04/2011 20:59:18
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01508206
Message ID:
01508285
Views:
42
That was exactly it. Thanks Bonnie!


>Well, I don't really know the syntax either, but if I were to try it myself, I'd try something like this:
>
>        retVal = (from p in dc.tblProjects
>                    where p.ProjectId == ProjectId
>                    select new ProjectModel
>                    {
>                        ProjectId = p.ProjectId,
>                        UserId = p.UserId,
>                        PrimaryWarehouse = (from pw in dv.tblWarehouse
>                            where pw.WarehouseID = p.PrimaryWhseId
>                            select new WarehouseModel{whatever fields go here}
>                            ).FirstOrDefault(),
>                        SecondaryWarehouse = (from sw in dv.tblWarehouse
>                            where sw.WarehouseID = p.SecondaryWhseId.Value
>                            select new WarehouseModel{whatever fields go here}
>                            ).FirstOrDefault(),
>                        ProjectType = getProjectTypeEnum(p.ProjectType.Value),
>                        CustomerCode = p.CustomerCode,
>                        CustomerName = p.CustomerName,
>                        ProjectName = p.ProjectName,
>                        ProjectNum = p.ProjectNum,
>                        Date = p.Date,
>                        Comments = p.Comments
>                    }
>                    ).FirstOrDefault();
>
>
>Will that work for you?
>
>~~Bonnie
>
>
>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform