CodeSmith Community
Your Code. Your Way. Faster!

View GetAll() to generate TList<TableName> instead of VList<ViewName>

Latest post 02-21-2008 8:16 PM by golan. 6 replies.
  • 02-19-2008 2:49 AM

    • golan
    • Not Ranked
    • Joined on 12-07-2007
    • Posts 8
    • Points 160

    View GetAll() to generate TList<TableName> instead of VList<ViewName>

     I've made a view (called: MaleCustomers) which shows all male customers (select customer.* from customers where gender = 'Male').

    The view returns an exact structure of the customer table.

    .netTiers generates an entity MaleCustomers and a provider MaleCustomersProvider which has a method GetAll() which returns VList<MaleCustomers>.

    is there a way to get MaleCustomersProvider.GetAll() return a TList<Customer> instead? 

     

    Filed under:
    • Post Points: 35
  • 02-19-2008 6:08 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 251
    • Points 6,415

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

    For views, the return type is VList... no way to change that. );

     

    You can create custom stored procedures to return costumers by Gender. Views with the same columns of tables make no sense to me..

     

    TList<Costumer> maleCostumers =  CostumerProvider.GetByGender('Male');

    • Post Points: 35
  • 02-19-2008 7:54 AM In reply to

    • golan
    • Not Ranked
    • Joined on 12-07-2007
    • Posts 8
    • Points 160

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

    vbandrade you saved me :)

    I used views instead of stored procedure because i thought the result of a stored procedure would be the same (VList<ProcName>).

    I followed your advice and search this forum for custom stored procedures and found just what I was looking for.

    If I wish to have a query return a result based on a specific table I sould create a custom stored procedure and name it: _TableName_ProcName

    and the result would be of TList<TableName> instead of VList<ProcName>.

    example: _Customer_GetByGender will return TList<Customer>.

     I hope this helps other new .netTiers users like me.

    Thanks again vbandrade.

    • Post Points: 35
  • 02-19-2008 10:06 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 924
    • Points 34,750

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

    Would it not be better to have an index on the Gender column in the first place? You will then get a GetByGender method generated anyway.

    It might even be better to split the Gender field out to a an enum lookup table and then have a FK on the Customer.  Then rather than having to pass in a hard coded string such as "Male" or "Female" you'll be able to do:

    CustomerProvider.GetByGender( (int)Gender.Male) or my preference

    CustomerService customerService = new CustomerService();
    TList<Customer> customerList = customerService.GetByGender((int)Gender.Male);

     

    which in my opinion is better because any changes to Gender will be caught at compile time and it should be slightly faster as the index will be over a numeric value (supposingh you use an Identity int)

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 90
  • 02-20-2008 8:40 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 251
    • Points 6,415

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

    Swim, That´s why you´re the none in charge. (;

     

    Golan, swim´s solution is waaay cleaner and nice than mine and also performs better..

    • Post Points: 5
  • 02-20-2008 2:27 PM In reply to

    • golan
    • Not Ranked
    • Joined on 12-07-2007
    • Posts 8
    • Points 160

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

     Thank you swin for your solution.

    I'm new to .netTiers.

    could you please tell me how to create an enum lookup table?

    • Post Points: 5
  • 02-21-2008 8:16 PM In reply to

    • golan
    • Not Ranked
    • Joined on 12-07-2007
    • Posts 8
    • Points 160

    Re: View GetAll() to generate TList<TableName> instead of VList<ViewName>

     found it

    http://community.codesmithtools.com/forums/t/7263.aspx

     

    http://community.codesmithtools.com/forums/t/1095.aspx 

    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems