Linq error: 'InvcHead' is a type which is not valid in the given context

I am writing some code using Linq and am getting errors for my linq statement:
“InvcHead” is a type which is not valid in the given context
“OrderHed” is a type which is not valid in the given context

I downloaded LINQPad and the Epicor_10_LINQPad_Starter.linq and am getting the same error in Linqpad. what could i be doing wrong?

here is my ‘query’

var orderNum = (from g in GLJrnDtl
join i in InvcHead
on new { comp = g.Company, invc = g.LegalNumber} equals new {comp = i.Company, invc = i.InvoiceNum }
join o in OrderHed
on new { comp = i.Company, order = i.OrderNum} equals new {comp = o.Company, order = o.OrderNum }
select new { HistoryRow = g.SysRowID, OrderNum = i.InvoiceNum });

Do the table names need to be preceded by Db. ??

As Calvin mentioned there should be a database context so you can access the tables.

Well, I added the database context and that throws an error…

var orderNum = (from g in ERP.GLJrnDtl
join i in ERP.InvcHead
on new { comp = g.Company, invc = g.LegalNumber} equals new {comp = i.Company, invc = i.InvoiceNum }
join o in ERP.OrderHed
on new { comp = i.Company, order = i.OrderNum} equals new {comp = o.Company, order = o.OrderNum }
select new { HistoryRow = g.SysRowID, OrderNum = i.InvoiceNum });

3 errors, all the same:
The name ‘ERP’ does not exist in the current context

Under References there is System.XML.Linq. There is nothing under Usings. Am I missing something?

try it with literally Db.

I’m only guessing this, as other LINQ examples always prefix the table name with Db. like:

string MyData = Db.QuoteHed.Where( r =>r.Company == MyCompany && r.QuoteNum == QuoteToFind).Select( r =>r.MyUDField_c ).DefaultIfEmpty("Not Found").FirstOrDefault();

I know that’s not using the same style as your LINQ code, but the tables should probably be referenced the same way.

OK! adding Db. did work! now I have another error

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to ‘Join’
Hmmm

GLJrnDtl.LegalNumber is of type nvchar, while InvcHead.InvoiceNum is type Int

Yes, I knew that - I was able to get it to work (link) in a BAQ, and forgot that bit while fighting with the other errors. That is the actual link i have to use! What the heck!!! I was hoping to use a cast or some such, but it doesn’t look like it.

Why not use GLJrnDtl.ARInvoiceNum ?