Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:53:05+00:00 2026-06-06T04:53:05+00:00

var result = (from p in productInQuery join o in orderInfoQuery on p.refNo equals

  • 0
var result = (from p in productInQuery
      join o in orderInfoQuery on p.refNo equals o.refNo
      join x in productQuery on p.productNo equals x.no
      join t in productOutQuery on p.no equals t.productInNo into productIn
      from t in productIn.DefaultIfEmpty()
      //let dateOut = (from m in orderInfoQuery where m.refNo == t.refNo select m.delivered).FirstOrDefault()
      orderby o.processDate descending
      select new
      {     
          modelNo = x.modelNo,
          mfgNo = p.mfgNo,
          serialNo = p.serialNo,
          poNo = p.poNo,
          lbs = p.lbs,
          width = p.width,
          height = p.height,
          depth = p.depth,
          qty = p.qty,
          dateIn = o.processDate,
          dateOut = (DateTime?)(from m in orderInfoQuery where m.refNo == t.refNo select m.processDate).FirstOrDefault()
      }).ToArray();

I want to add this result into iTextSharp table cell.

but I don’t know how to do,

I tried,

int resultSize = result.Length;

/*
for (int j = 0; j < resultSize; j++)
{
    table.AddCell(result[j]);
}
*/

foreach (string[] test in result) //Error : Unable to cast object of type 
{
    int testSize = test.Length;
    for (int j = 0; j < testSize; j++)
    {
        table.AddCell(test[j]);
    }
}

but I lost way 🙁

anybody knows, please advice me~

[EDIT]

int resultSize = result.Length; //192

enter image description here

test does have a fields…

[EDIT 2]

Actually the result be returned from Model.

PJ.WebUI.Models Reports Class

public class Reports 
{
  public Array GetTransaction(){
    OrdersRepository ordersRepository = new OrdersRepository();
    var productInQuery = ordersRepository.ProductIn;
    var productOutQuery = ordersRepository.ProductOut;
    var productQuery = ordersRepository.Product;
    var orderInfoQuery = ordersRepository.OrderInfo;
    var result = (from p in productInQuery
      join o in orderInfoQuery on p.refNo equals o.refNo
      join x in productQuery on p.productNo equals x.no
      join t in productOutQuery on p.no equals t.productInNo into productIn
      from t in productIn.DefaultIfEmpty()
      //let dateOut = (from m in orderInfoQuery where m.refNo == t.refNo select m.delivered).FirstOrDefault()
      orderby o.processDate descending
      select new
      {     
          modelNo = x.modelNo,
          mfgNo = p.mfgNo,
          serialNo = p.serialNo,
          poNo = p.poNo,
          lbs = p.lbs,
          width = p.width,
          height = p.height,
          depth = p.depth,
          qty = p.qty,
          dateIn = o.processDate,
          dateOut = (DateTime?)(from m in orderInfoQuery where m.refNo == t.refNo select m.processDate).FirstOrDefault()
      }).ToArray();
    return result;
  }
}

And in controller call the method to get the result.

Reports reposrts = new Reports();
var result = reposrts.GetTransaction();

..

foreach (var test in result)
{
     table.AddCell(test.modelNo);
}

Then

Error   1   'object' does not contain a definition for 'modelNo' and no extension method 'modelNo' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

So,

I move the model method into controller method (put all together in same method) and run. then it works!.

but the result be used in the other controller too. so I want to keep the result in Model class to reuse.

I want to know why it does not work if the result query is not in same method.

could you help me a little more please?

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:53:07+00:00Added an answer on June 6, 2026 at 4:53 am

    ‘result’ will be an array of the anonymous type you selected to, not an array of string arrays, which is why you are getting an error in the foreach loop.

    Your loop should probably look more like the following:

    foreach (var test in result)  
    { 
        table.AddCell(test.modelNo);
        table.AddCell(test.mfgNo);
        table.AddCell(test.serialNo);
        // etc
    } 
    

    @Edit 2:

    Because the result of GetTransaction() is ‘Array’, the calling method has no idea what the type is, it just sees it as an array of objects, and, because it is an anonymous type, you can’t (reasonably) cast it back to the expected type.

    I think your best bet in this case would be to make a new class which has the properties you want to return, e.g.:

    public class Transaction
    {
        public string ModelNo { get; set; }
        public string MfgNo { get; set; }
        public string SerialNo { get; set; }
       // etc. - but with the correct types for the properties
    }
    

    Then change the linq query to select into this type, instead of the anonymous type, e.g.:

    ...
    orderby o.processDate descending       
    select new Transaction
    {            
        ModelNo = x.modelNo,       
        MfgNo = p.mfgNo,       
        SerialNo = p.serialNo,
        // etc.
    ...
    

    And change the return type of GetTransaction() from Array to Transaction[].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var result = (from p in productInQuery join o in orderInfoQuery on p.refNo equals
var result = from lr in _db.LeaveRequest join th in _db.TotalHourslu on lr.TotalHoursEffect equals
var result = from lr in _db.LeaveRequest join th in _db.TotalHourslu on lr.TotalHoursEffect equals
var result = from p in dc.People join d in dc.Departments on p.fk_dep_id equals
I have this expression: var result = from pav in ProductAttributes join id in
I have following query: var result = ( from role in db.Roles join user
How to Put the following query result into a List var result = from
OrdersRepository ordersRepository = new OrdersRepository(); var productInQuery = ordersRepository.ProductIn; var orderInfoQuery = ordersRepository.OrderInfo; var
I have var result = (from rev in Revisions join usr in Users on
I have a LINQ query: var result = from mt in MessageTypes join mtfmt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.