Click here to Skip to main content
15,919,245 members
Home / Discussions / C#
   

C#

 
GeneralRe: Integers to Float IEEE 754 Pin
Member 148721281-Jul-20 5:44
Member 148721281-Jul-20 5:44 
GeneralRe: Integers to Float IEEE 754 Pin
Luc Pattyn1-Jul-20 5:50
sitebuilderLuc Pattyn1-Jul-20 5:50 
GeneralRe: Integers to Float IEEE 754 Pin
Member 148721281-Jul-20 6:08
Member 148721281-Jul-20 6:08 
GeneralRe: Integers to Float IEEE 754 Pin
Luc Pattyn1-Jul-20 6:12
sitebuilderLuc Pattyn1-Jul-20 6:12 
GeneralRe: Integers to Float IEEE 754 Pin
Member 148721281-Jul-20 6:18
Member 148721281-Jul-20 6:18 
GeneralRe: Integers to Float IEEE 754 Pin
Member 148721281-Jul-20 8:09
Member 148721281-Jul-20 8:09 
GeneralRe: Integers to Float IEEE 754 Pin
Luc Pattyn1-Jul-20 9:29
sitebuilderLuc Pattyn1-Jul-20 9:29 
QuestionHow can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w30-Jun-20 11:14
arnold_w30-Jun-20 11:14 
AnswerRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Dave Kreskowiak30-Jun-20 11:18
mveDave Kreskowiak30-Jun-20 11:18 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w30-Jun-20 11:36
arnold_w30-Jun-20 11:36 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Dave Kreskowiak30-Jun-20 11:59
mveDave Kreskowiak30-Jun-20 11:59 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Luc Pattyn30-Jun-20 11:48
sitebuilderLuc Pattyn30-Jun-20 11:48 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Dave Kreskowiak30-Jun-20 11:59
mveDave Kreskowiak30-Jun-20 11:59 
AnswerRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Luc Pattyn30-Jun-20 12:35
sitebuilderLuc Pattyn30-Jun-20 12:35 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w30-Jun-20 19:52
arnold_w30-Jun-20 19:52 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
kalberts1-Jul-20 0:09
kalberts1-Jul-20 0:09 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w1-Jul-20 0:15
arnold_w1-Jul-20 0:15 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Luc Pattyn1-Jul-20 1:08
sitebuilderLuc Pattyn1-Jul-20 1:08 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w1-Jul-20 1:58
arnold_w1-Jul-20 1:58 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
Luc Pattyn1-Jul-20 2:08
sitebuilderLuc Pattyn1-Jul-20 2:08 
GeneralRe: How can I find out what "USB Serial Device" is called in all other languages? Pin
arnold_w1-Jul-20 2:12
arnold_w1-Jul-20 2:12 
QuestionVS2017 publish project to .exe without manifest files Pin
Member 1487747430-Jun-20 10:35
Member 1487747430-Jun-20 10:35 
AnswerRe: VS2017 publish project to .exe without manifest files Pin
Dave Kreskowiak30-Jun-20 11:15
mveDave Kreskowiak30-Jun-20 11:15 
QuestionOptimize Linq To SQL Query Pin
Kevin Marois30-Jun-20 8:21
professionalKevin Marois30-Jun-20 8:21 
This query is bit long, and it returns the correct data, but it takes about 4 minutes to run. I'd like to speed it up. The first part with the query runs pretty quick. The FOREACH loop part is the bottleneck.

Inside the FOREACH are 4 queries. They are all the same, except they pull from 4 different tables (JobHardwareVendors, JobLumberVendors, EquipmentHardwareVendors, TrussHardwareVendors). Those tables each have the same structure.

Those inner queries look like this:
/*********************************************************
    * Get the Hardware Vendors
    *********************************************************/
var vendors = (from v in db.JobHardwareVendors
                join c in db.Companies on v.VendorId equals c.Id
                where v.JobId == result.Id &&
                    !v.DeletedDT.HasValue
                select new CompanyHeaderEntity
                {
                    Id = c.Id,
                    CompanyName = c.CompanyName,
                    StatusId = c.StatusId
                }).Distinct().ToList();
result.HardwareCompanies.AddRange(vendors.Where(x => x.StatusId == companyStatuseActive.Id));

// Get the vendor's initials
foreach (var vendor in vendors)
{
    result.VendorInitials += GetInitials(vendor.CompanyName) + ",";
}
Here's the entire method
public async Task<List<TimelineReportEntity>> GetTimelineReportData(GenericReportArgsEntity reportArgs)
{
    var t = await Task.Factory.StartNew(() =>
    {
        List<TimelineReportEntity> results = null;

        using (var db = GetDataContext())
        {
            try
            {
                IQueryable<TimelineReportEntity> query = (from j in db.Jobs
                                                            join p in db.Projects on j.ProjectId equals p.Id
                                                            join c in db.Companies on p.CompanyId equals c.Id
                                                            join e in db.Employees on j.ForemanId equals e.Id into ep
                                                            from e in ep.DefaultIfEmpty()
                                                            join lc in db.Companies on j.LumberVendorId equals lc.Id into elc
                                                            from lc in elc.DefaultIfEmpty()
                                                            join hc in db.Companies on j.HardwareVendorId equals hc.Id into ehc
                                                            from hc in ehc.DefaultIfEmpty()
                                                            join tc in db.Companies on j.HardwareVendorId equals tc.Id into etc
                                                            from tc in etc.DefaultIfEmpty()
                                                            where !j.DeletedDT.HasValue
                                                            select new TimelineReportEntity
                                                            {
                                                                Id = j.Id,
                                                                JobId = j.JobNumber,
                                                                ProjectId = p.Id,
                                                                ProjectName = p.ProjectName,
                                                                CompanyId = c.Id,
                                                                CompanyName = c.CompanyName,
                                                                ForemanId = e.Id,
                                                                ForemanName = $"{e.FirstName} {e.LastName}",
                                                                Phase = j.Phase,
                                                                Quantity = j.Quantity,
                                                                Notes = j.Notes,
                                                            });

                // Create the predicate builder
                ExpressionStarter<TimelineReportEntity> predicate = null;

                if (reportArgs.IncludeAllProjects &&
                    reportArgs.IncludeAllCompanies &&
                    reportArgs.IncludeAllForemen)
                {
                    results = query.ToList();
                }
                else
                {
                    predicate = PredicateBuilder.New<TimelineReportEntity>();

                    if (!reportArgs.IncludeAllProjects)
                    {
                        foreach (var projectId in reportArgs.ProjectIds)
                        {
                            predicate = predicate.Or(p => p.ProjectId == projectId);
                        }
                    }

                    if (!reportArgs.IncludeAllCompanies)
                    {
                        foreach (var companyId in reportArgs.CompanyIds)
                        {
                            predicate = predicate.Or(p => p.CompanyId == companyId);
                        }
                    }

                    if (!reportArgs.IncludeAllForemen)
                    {
                        foreach (var foremanId in reportArgs.ForemenIds)
                        {
                            predicate = predicate.Or(p => p.ForemanId == foremanId);
                        }
                    }

                    results = query.Where(predicate).ToList();
                }

                var companyStatuses = GetLookups(Constants.LookupCategoryGenericFilters);
                var companyStatuseActive = companyStatuses.FirstOrDefault(x => x.AppCode == Constants.LookupCategoryGenericFiltersTypeActive);

                foreach (var result in results)
                {
                    result.ForemanInitials = result.ForemanName;

                    /*********************************************************
                        * Get the Hardware Vendors
                        *********************************************************/
                    var vendors = (from v in db.JobHardwareVendors
                                    join c in db.Companies on v.VendorId equals c.Id
                                    where v.JobId == result.Id &&
                                        !v.DeletedDT.HasValue
                                    select new CompanyHeaderEntity
                                    {
                                        Id = c.Id,
                                        CompanyName = c.CompanyName,
                                        StatusId = c.StatusId
                                    }).Distinct().ToList();
                    result.HardwareCompanies.AddRange(vendors.Where(x => x.StatusId == companyStatuseActive.Id));

                    // Get the vendor's initials
                    foreach (var vendor in vendors)
                    {
                        result.VendorInitials += GetInitials(vendor.CompanyName) + ",";
                    }

                    /*********************************************************
                        * Get the Lumber Vendors
                        *********************************************************/
                    vendors = (from v in db.JobLumberVendors
                                join c in db.Companies on v.VendorId equals c.Id
                                where v.JobId == result.Id &&
                                        !v.DeletedDT.HasValue
                                select new CompanyHeaderEntity
                                {
                                    Id = c.Id,
                                    CompanyName = c.CompanyName,
                                    StatusId = c.StatusId
                                }).Distinct().ToList();
                    result.LumberCompanies.AddRange(vendors.Where(x => x.StatusId == companyStatuseActive.Id));

                    // Get the vendor's initials
                    foreach (var vendor in vendors)
                    {
                        result.VendorInitials += GetInitials(vendor.CompanyName) + ",";
                    }

                    /*********************************************************
                        * Get the Equipment Vendors
                        *********************************************************/
                    vendors = (from v in db.JobEquipmentVendors
                                join c in db.Companies on v.VendorId equals c.Id
                                where v.JobId == result.Id &&
                                        !v.DeletedDT.HasValue
                                select new CompanyHeaderEntity
                                {
                                    Id = c.Id,
                                    CompanyName = c.CompanyName,
                                    StatusId = c.StatusId
                                }).Distinct().ToList();
                    result.EquipmentCompanies.AddRange(vendors.Where(x => x.StatusId == companyStatuseActive.Id));

                    // Get the vendor's initials
                    foreach (var vendor in vendors)
                    {
                        result.VendorInitials += GetInitials(vendor.CompanyName) + ",";
                    }

                    /*********************************************************
                        * Get the Truss Vendors
                        *********************************************************/
                    vendors = (from v in db.JobTrussVendors
                                join c in db.Companies on v.VendorId equals c.Id
                                where v.JobId == result.Id &&
                                        !v.DeletedDT.HasValue
                                select new CompanyHeaderEntity
                                {
                                    Id = c.Id,
                                    CompanyName = c.CompanyName,
                                    StatusId = c.StatusId
                                }).Distinct().ToList();
                    result.TrussCompanies.AddRange(vendors.Where(x => x.StatusId == companyStatuseActive.Id));

                    // Get the vendor's initials
                    foreach (var vendor in vendors)
                    {
                        result.VendorInitials += GetInitials(vendor.CompanyName) + ",";
                    }

                    // Remove trailing comma from vendor initials
                    if (!string.IsNullOrEmpty(result.VendorInitials))
                    {
                        result.VendorInitials = result.VendorInitials.TrimEnd(',');
                    }

                    /*********************************************************
                        * Get the latest Start Date
                        *********************************************************/
                    var startDateRevision = GetJobStartDateRevisions(result.Id).OrderByDescending(x => x.Revision).FirstOrDefault();

                    if (startDateRevision != null)
                    {
                        result.StartDate = startDateRevision.StartDate;
                        result.WeekGroup = result.StartDate.StartOfWeek(DayOfWeek.Monday);
                        result.FromDate = reportArgs.FromDate;
                        result.ToDate = reportArgs.ToDate;
                    }
                }

                results = results.Where(x => x.StartDate >= reportArgs.FromDate && x.StartDate <= reportArgs.ToDate).OrderBy(x => x.StartDate).ToList();
            }
            catch (Exception e)
            {
                throw;
            }
        }

        return results.ToList();
    });

    return t;
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

QuestionC# Pin
Member 1258896327-Jun-20 5:30
Member 1258896327-Jun-20 5:30 

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.