John
John

Reputation: 3945

return record through LINQ statement

DataContext db = new DataContext();
Select_Utilities SelectedUtility = (from su in db.Select_Utilities
                                    where su.id == SelectUtilityId
                                    && su.Worksite_Id == WorksiteId
                                     && su.Utility_Company.id == UtilityCompanyId
                                     select su).FirstOrDefault();

then I wanted to say SelectedUtility.comment = "whatever the comment may be";

BUT getting ERROR: cannot implicity convert type 'Select_Utility' to 'Select_Utilities'

with 'FirstOrDefault' in statement....any advice?

Thanks

Upvotes: 1

Views: 42

Answers (2)

D Stanley
D Stanley

Reputation: 152626

I'm guessing Select_Utilities is the name of your Entity table which ruturns a collection of Select_Utility objects. Try:

Select_Utility selectedUtility = (from su in db.Select_Utilities
                                  where su.id == SelectUtilityId
                                     && su.Worksite_Id == WorksiteId
                                     && su.Utility_Company.id == UtilityCompanyId
                                  select su).FirstOrDefault();

Upvotes: 1

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

Change result type to Select_Utility

Select_Utility SelectedUtility =  // here
   (from su in db.Select_Utilities
    where su.id == SelectUtilityId && 
          su.Worksite_Id == WorksiteId && 
          su.Utility_Company.id == UtilityCompanyId
    select su).FirstOrDefault();

Upvotes: 3

Related Questions