Click here to Skip to main content
15,501,294 members
Home / Discussions / C#
   

C#

 
GeneralRe: Serialize class with multiple different schemas Pin
hpjchobbes27-Dec-17 4:26
Memberhpjchobbes27-Dec-17 4:26 
GeneralRe: Serialize class with multiple different schemas Pin
Gerry Schmitz28-Dec-17 7:28
mveGerry Schmitz28-Dec-17 7:28 
QuestionType Casting from OleDb Value Types Returns Invalid Cast Exception Pin
User9874326-Dec-17 0:09
professionalUser9874326-Dec-17 0:09 
AnswerRe: Type Casting from OleDb Value Types Returns Invalid Cast Exception Pin
Gerry Schmitz26-Dec-17 13:28
mveGerry Schmitz26-Dec-17 13:28 
GeneralRe: Type Casting from OleDb Value Types Returns Invalid Cast Exception Pin
User9874326-Dec-17 13:52
professionalUser9874326-Dec-17 13:52 
GeneralRe: Type Casting from OleDb Value Types Returns Invalid Cast Exception Pin
User9874326-Dec-17 14:02
professionalUser9874326-Dec-17 14:02 
QuestionAwait/Async Question Pin
Kevin Marois24-Dec-17 11:51
professionalKevin Marois24-Dec-17 11:51 
AnswerRe: Await/Async Question Pin
Dave Kreskowiak24-Dec-17 16:15
mveDave Kreskowiak24-Dec-17 16:15 
You only need the async modifier if you've got an await in the method. All this method needs to do is return a Task or some kind, which your method isn't doing. A dirty conversion of your code to returning a Task would be:
C#
public Task<CompanyEntity> GetCompany(int id)
{
    return Task.Factory.StartNew<CompanyEntity>(() =>
    {
        using (var db = new JayhawkDB())
        {
            CompanyEntity results = null;
 
            var query = from x in db.Companies
                        where x.Id == id
                        select x;
 
            var record = query.FirstOrDefault<Company>();
 
            results = new CompanyEntity
            {
                Id = record.Id,
                CreatedById = record.CreatedById,
                CreatedDT = record.CreatedDt,
                DeletedById = record.DeletedById.GetValueOrDefault(),
                DeletedDT = record.DeletedDt.GetValueOrDefault(),
                CompanyName = record.CompanyName,
                Abbreviation = record.Abbreviation,
                Notes = record.Notes
            };
 
            return results;
        });
    }
}

The caller awaits this code, not the other way around.

Oh, and that try/catch block is pretty much useless if all you're going to do is catch all Exceptions and just re-throw them.

System.ItDidntWorkException: Something didn't work as expected.

C# - How to debug code[^].
Seriously, go read these articles.

Dave Kreskowiak

GeneralRe: Await/Async Question Pin
Kevin Marois24-Dec-17 16:22
professionalKevin Marois24-Dec-17 16:22 
QuestionGetting a list of Key pressed Pin
Kenneth Haugland22-Dec-17 10:52
mvaKenneth Haugland22-Dec-17 10:52 
AnswerRe: Getting a list of Key pressed Pin
Kenneth Haugland23-Dec-17 6:10
mvaKenneth Haugland23-Dec-17 6:10 
AnswerRe: Getting a list of Key pressed Pin
Gerry Schmitz23-Dec-17 6:58
mveGerry Schmitz23-Dec-17 6:58 
GeneralRe: Getting a list of Key pressed Pin
Kenneth Haugland23-Dec-17 11:14
mvaKenneth Haugland23-Dec-17 11:14 
GeneralRe: Getting a list of Key pressed Pin
Gerry Schmitz23-Dec-17 19:38
mveGerry Schmitz23-Dec-17 19:38 
SuggestionMessage Closed Pin
22-Dec-17 0:20
professionalmatthewproctor22-Dec-17 0:20 
GeneralRe: Looking for feedback for new .Net / C# error tracking and reporting tool Pin
OriginalGriff22-Dec-17 1:57
mveOriginalGriff22-Dec-17 1:57 
GeneralRe: Looking for feedback for new .Net / C# error tracking and reporting tool Pin
Eddy Vluggen22-Dec-17 5:08
professionalEddy Vluggen22-Dec-17 5:08 
QuestionPopulate graph from datagridview Pin
Member 1125947820-Dec-17 23:51
MemberMember 1125947820-Dec-17 23:51 
GeneralRe: Populate graph from datagridview Pin
Ralf Meier21-Dec-17 3:50
mveRalf Meier21-Dec-17 3:50 
GeneralRe: Populate graph from datagridview Pin
Member 1125947821-Dec-17 3:54
MemberMember 1125947821-Dec-17 3:54 
AnswerRe: Populate graph from datagridview Pin
Gerry Schmitz21-Dec-17 11:58
mveGerry Schmitz21-Dec-17 11:58 
QuestionHow can I make a Location-like collapsible properties? Pin
Member 1358759420-Dec-17 19:52
MemberMember 1358759420-Dec-17 19:52 
QuestionRe: How can I make a Location-like collapsible properties? Pin
Richard MacCutchan20-Dec-17 22:36
mveRichard MacCutchan20-Dec-17 22:36 
AnswerRe: How can I make a Location-like collapsible properties? Pin
Ralf Meier21-Dec-17 3:42
mveRalf Meier21-Dec-17 3:42 
AnswerRe: How can I make a Location-like collapsible properties? Pin
Gerry Schmitz21-Dec-17 11:53
mveGerry Schmitz21-Dec-17 11:53 

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.