in

CodeSmith Community

Your Code. Your Way. Faster!

.NetTiers - Loading specific fields per entity

Last post 02-15-2008 1:59 PM by vbandrade. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-14-2008 11:08 AM

    • nmckenzie
    • Not Ranked
    • Joined on 10-22-2007
    • Indianapolis, IN
    • Posts 2
    • Points 70

    .NetTiers - Loading specific fields per entity

    Is there a way to populate only certain fields when retrieving an entity?

    I.E.
    DataRepository.ContactProvider.GetAll()

    but, I would really only like to get back the SSN of the contact and not the entire entity.

     Thanks in advance

    • Post Points: 35
  • 02-14-2008 2:02 PM In reply to

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

    Re: .NetTiers - Loading specific fields per entity

    no, the whole point of using nettiers is that the entities are a reflection of the model in your database.

    of course you can always write a custom stored proc to possible do what you want, but that is then getting away from what nettiers is about.

    unless you're processing 1000's of records in one go i wouldn't worry about it. our system does millions of read/updates a day without any problems

    hth

    swin

    -------------------------------------------------
    Member of the .NetTiers team
    -------------------------------------------------
    • Post Points: 35
  • 02-14-2008 2:09 PM In reply to

    • nmckenzie
    • Not Ranked
    • Joined on 10-22-2007
    • Indianapolis, IN
    • Posts 2
    • Points 70

    Re: .NetTiers - Loading specific fields per entity

    Swin,

    Thanks for the reply.  I understand.

     

    I originally started with Llblgen O/R Mapper early in my career and was just thinking of something like this (pasted from their documentation):

    Entity fetch example

    The following example uses the default constructor of ExcludeIncludeFieldsList, which sets the

    ExcludeContainedFields property to true. This means that the fields added to it are meant to be excluded. It

    will fetch all Northwind customers but with some fields excluded, which are after the fetch loaded into the

    entities again.

    C#

    VB.NET

    // C#

    ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();

    excludedFields.Add(CustomerFields.ContactName);

    excludedFields.Add(CustomerFields.Country);

    // fetch a collection of customers.

    EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();

    SortExpression sorter =

    new SortExpression(CustomerFields.CustomerId | SortOperator.Descending);

    using(DataAccessAdapter adapter = new DataAccessAdapter())

    {

    adapter.FetchEntityCollection(customers, null, 0, sorter, null, excludedFields);

    }

    // fetch a single customer

    CustomerEntity c = new CustomerEntity("CHOPS");

    using(DataAccessAdapter adapter = new DataAccessAdapter())

    {

    adapter.FetchEntity(c, null, null, excludedFields);

    }

    // ...

    // load the excluded fields into the entities already loaded:

    using(DataAccessAdapter adapter = new DataAccessAdapter())

    {

    adapter.FetchExcludedFields(customers, excludedFields);

    adapter.FetchExcludedFields(c, excludedFields);

    }

    ' VB.NET

    Dim excludedFields As New ExcludeIncludeFieldsList()

    excludedFields.Add(CustomerFields.ContactName)

    excludedFields.Add(CustomerFields.Country)

    ' fetch a collection of customers.

    Dim customers As New EntityCollection(Of CustomerEntity)()

    Dim sorter As New SortExpression(CustomerFields.CustomerId Or SortOperator.Descending)

    Using adapter As New DataAccessAdapter()

    adapter.FetchEntityCollection(customers, Nothing, 0, sorter, Nothing, excludedFields)

    End Using

    ' fetch a single customer

    Dim c As New CustomerEntity("CHOPS")

    Using adapter As New DataAccessAdapter()

    adapter.FetchEntity(c, Nothing, Nothing, excludedFields)

    End Using

    • Post Points: 35
  • 02-15-2008 1:59 PM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 130
    • Points 3,060

    Re: .NetTiers - Loading specific fields per entity

    Check this post:

     

    http://community.codesmithtools.com/forums/thread/29582.aspx 

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