Error: object does not contain a definition for fieldname
Code |
Description |
CS1061 |
'object' does not contain a definition for 'IDSearchAgent' and no extension method 'IDSearchAgent' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) |
Problem:
If you create combined data of a query in Linq, then at the end of the data query you can either completely output the data tables with all fields or make a well-defined field specification which result fields are required for the output.
This information leads to an error:
Query from join .. select searchAgent.IDSearchAgent, asp.Email).Take(3000); |
Solution:
You have to change the output to new {..} pack
select new { searchAgent.IDSearchAgent, q3.Email }).Take(3000); |
Not correct:
Error:
Wrong field definition in the query
//--< Get Linq.Query >-- var query = (from searchAgent in _dbContext.tbl_SearchAgents join users in _dbContext.tbl_Users on searchAgent.IDOwner equals users.IDUser into searchagents_with_user
from q2 in searchagents_with_user.DefaultIfEmpty() join asp in _dbContext.Users on q2.IDAspNetUser equals asp.Id into searchagents_with_user_emails
from q3 in searchagents_with_user_emails.DefaultIfEmpty()
orderby searchAgent.IDOwner descending, searchAgent.IDSearchAgent descending select searchAgent.IDSearchAgent, asp.Email).Take(3000); //--</ Get Linq.Query >--
|
Solution:
//--< Get Linq.Query >-- var query = (from searchAgent in _dbContext.tbl_SearchAgents join users in _dbContext.tbl_Users on searchAgent.IDOwner equals users.IDUser into searchagents_with_user
from q2 in searchagents_with_user.DefaultIfEmpty() join asp in _dbContext.Users on q2.IDAspNetUser equals asp.Id into searchagents_with_user_emails
from q3 in searchagents_with_user_emails.DefaultIfEmpty()
orderby searchAgent.IDOwner descending, searchAgent.IDSearchAgent descending select new { searchAgent.IDSearchAgent, q3.Email }).Take(3000); //--</ Get Linq.Query >--
|
Linq is the modern creation of SQL queries in collaboration with EF EntityFramework.