Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListView height inside of a StackPanel - problem...
Message
From
25/06/2008 00:40:41
 
 
To
24/06/2008 16:10:21
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01325263
Message ID:
01326550
Views:
14
>>pull back the entire object

That's pretty much what I am doing. VFP was very flexible for things like this. Some days I really miss that.


>It just seems insane to create another light-weight pseudo-class of Customers just to handle a Linq collection that returns only the essential fields I want. I already have a full class definition, from the dbml that I wish I could use as the object type. Yes, maybe it would be mostly empty (using only the fields that are pulled during the query), but much less code to build and maintain.
>
>Anyway, for now, I've resolved to pull back the entire object (not just certain fields) so I can cast it as the full existing class from the dbml.
>
>
>
>>
>>You have to put a constructor on your class to take the fields like I did here:
>>
>>>>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 then use that constructor in your select:
>>
>>>>
>>>>            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) ;
>>>>
>>
>>Linq does create a new class for you when you do a select, but it only has local scope so it's not very useful.
>>
>>If it's one of your DBML classes they are defined as partial, so you can add the new constructor to it. (Don't know if there would be any side effects from selecting from one DBML class into another. Such as it getting confused about it being a new item.)
>>
>>Rick Strahl has a good article on this: http://www.west-wind.com/weblog/posts/33570.aspx
>>
>>That's where I originally got this technique
>>
>>John
>>
>>
>>>
>>>            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
Reply
Map
View

Click here to load this message in the networking platform