Click here to Skip to main content
15,897,291 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to convert pdf to word(2003, 2007 and 2010)? Pin
Dave Kreskowiak11-Feb-17 4:56
mveDave Kreskowiak11-Feb-17 4:56 
AnswerRe: How to convert pdf to word(2003, 2007 and 2010)? Pin
Patrice T12-Feb-17 10:32
mvePatrice T12-Feb-17 10:32 
QuestionReturn List From Joined Tables Using LINQ Pin
Liagapi10-Feb-17 19:14
Liagapi10-Feb-17 19:14 
AnswerRe: Return List From Joined Tables Using LINQ Pin
Garth J Lancaster10-Feb-17 20:35
professionalGarth J Lancaster10-Feb-17 20:35 
GeneralRe: Return List From Joined Tables Using LINQ Pin
Liagapi10-Feb-17 23:11
Liagapi10-Feb-17 23:11 
GeneralRe: Return List From Joined Tables Using LINQ Pin
Garth J Lancaster11-Feb-17 1:39
professionalGarth J Lancaster11-Feb-17 1:39 
AnswerRe: Return List From Joined Tables Using LINQ Pin
Eddy Vluggen11-Feb-17 2:11
professionalEddy Vluggen11-Feb-17 2:11 
SuggestionRe: Return List From Joined Tables Using LINQ Pin
Richard Deeming12-Feb-17 1:38
mveRichard Deeming12-Feb-17 1:38 
Liagapi wrote:
IEnumerable<Employee> emps = db.Employees.ToList();
IEnumerable<Project> projs= db.Projects.ToList();
IEnumerable<Product> prods = db.Products.ToList();

Your code is loading the whole of those three tables into memory, before filtering for the specific product. That's going to be horribly inefficient.

Liagapi wrote:
string productId
where prd.productID == Convert.ToInt32(productId)

Your code is going to throw an exception if you pass in any string that can't be converted to an integer. Instead, you should change your parameter to be an integer, so that your expectations are obvious to the caller.

Liagapi wrote:
public List<string> GetProductDetails

If you want to return something other than a single string for each record, you're going to need to change the return type.


Liagapi wrote:
join prj in projs on e.EmployeeID equals prj.ProjectID
join prd in prods on e.EmployeeID equals prd.productID

Those join columns don't look right to me. Double-check how your models are related.

C#
public sealed class ProductDetails
{
    public string employee { get; set; }
    public string project { get; set; }
    public string product { get; set; }
}
...
public List<ProductDetails> GetProductDetails(int productId)
{
    using (var db = new ProductContext())
    {
        var productDetails = from e in db.Employees
                             join prj in db.Projects on e.EmployeeID equals prj.ProjectID // Is this the correct join?
                             join prd in prods on e.EmployeeID equals prd.productID // Is this the correct join?
                             where prd.productID == productId
                             select new { e.EmployeeName, prj.ProjectName, prd.ProductName };
        
        return productDetails.AsEnumerable().Select(x => new ProductDetails
        {
            employee = x.EmployeeName,
            project = x.ProjectName,
            product = x.ProductName
        }).ToList();
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Return List From Joined Tables Using LINQ Pin
Liagapi12-Feb-17 6:11
Liagapi12-Feb-17 6:11 
QuestionVirtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 9:12
qzzf1w10-Feb-17 9:12 
AnswerRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 11:40
mveGerry Schmitz10-Feb-17 11:40 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 11:51
qzzf1w10-Feb-17 11:51 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 12:21
mveGerry Schmitz10-Feb-17 12:21 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 12:37
qzzf1w10-Feb-17 12:37 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 12:45
mveGerry Schmitz10-Feb-17 12:45 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 13:01
qzzf1w10-Feb-17 13:01 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 13:17
mveGerry Schmitz10-Feb-17 13:17 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 13:21
qzzf1w10-Feb-17 13:21 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 13:36
mveGerry Schmitz10-Feb-17 13:36 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 14:08
qzzf1w10-Feb-17 14:08 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 14:24
mveGerry Schmitz10-Feb-17 14:24 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 18:45
qzzf1w10-Feb-17 18:45 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 19:10
mveGerry Schmitz10-Feb-17 19:10 
GeneralRe: Virtual Trackpad > WIndows... Pin
qzzf1w10-Feb-17 19:42
qzzf1w10-Feb-17 19:42 
GeneralRe: Virtual Trackpad > WIndows... Pin
Gerry Schmitz10-Feb-17 19:49
mveGerry Schmitz10-Feb-17 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.