Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListView height inside of a StackPanel - problem...
Message
From
24/06/2008 00:27:10
 
 
To
20/06/2008 13:32:54
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01325263
Message ID:
01326260
Views:
14
Why can't I cast this like I am trying to? Notice the casting in the last line.

It pulls a list of customers who have open orders. I only need CustNo and Company for my ListView, but I would take all customer fields if I have to. I'm trying to cast it to an exiting class type from my Linq-toSql definitions so I don't have to create and maintain another nearly identical custom class. I've tried IQueryable and IEnurable, but it doesn't work either way.
            IQueryable<customer_source> CustomerList = from a in
                                                           (from p in db.job_info
                                                            join c in db.customers on p.cust_num equals c.custno
                                                            where p.status == 'A'
                                                            orderby c.company
                                                            select new { custno = c.custno, company = c.company }
                                                            ).Distinct()
                                                       orderby a.company
                                                       select new customer_source { custno = a.custno, company = a.company };
This way works, but it gives me anonymous types in my ListView, which I don't like (after your teaching).
            var CustomerList = from a in
                                   (from p in db.job_info
                                    join c in db.customers on p.cust_num equals c.custno
                                    where p.status == 'A'
                                    orderby c.company
                                    select new { c.custno, c.company, c.phone, c.faxno }
                                    ).Distinct()
                               orderby a.company
                               select a;
>You need to get away from var because it won't pass between classes.
>
>Either pass the whole record:
>
>
>            IEnumerable<customer> customers = from a in db.customers
>                            where SqlMethods.Like(a.custno,CustomerFilter) || SqlMethods.Like(a.company,CustomerFilter)
>                            orderby a.custno
>                            select a;
>
>
>Or create a new class:
>
>
>  public class dataitem
>    {
>    public int custno { get; set; }
>    public string company { get; set; }
>    public string phone { get; set; }
>    public string faxno { get; set; }
>
>    public dataitem(int cno, string c, string p, string f)
>      {
>      custno = cno;
>      company = c;
>      phone = p;
>      faxno = f;
>      }
>    }
>
>
>And return it:
>
>
>            IEnumerable<dataitem> customers = from a in db.customers
>                            where SqlMethods.Like(a.custno,CustomerFilter) || SqlMethods.Like(a.company,CustomerFilter)
>                            orderby a.custno
>                            select new dataitem(a.custno, a.company, a.phone, a.faxno) ;
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform