CodeSmith Community
Your Code. Your Way. Faster!

PATCH: WsEntityProvider returns arbitrary new item for entities that don't exist

Latest post 05-22-2008 7:57 PM by blake05. 1 replies.
  • 04-20-2008 4:09 PM

    • BenAdams
    • Not Ranked
    • Joined on 02-04-2007
    • Lawton, Oklahoma
    • Posts 3
    • Points 105

    PATCH: WsEntityProvider returns arbitrary new item for entities that don't exist

    Hey Guys,

    I ran into something unexpected when I switched to the WebService Provider from the Sql provider...

    If a "Get" provider method returning a single entity instance is executed for an entity that doesn't exist, the webservice provider returns a newly instantiated "empty" object while the SqlProvider returns null.

    So, say there isn't a customer with customerID 123 and the following is executed

    Customer cust = DataRepository.CustomerProvider.GetByCustomerID(123);

    When using the SqlNetTiersProvider, cust will be null; but when using the WsetTiersProvider, cust will be a new Customer object (with Entitystate == EntityState.Added, CustomerID == 0, etc).

    Unless I'm missing something, I can't see why the providers should behave differently like this.  The reason for the difference lies in the logic that converts the proxy class to the entity class... it doesn't take into account a null return value from the webservice, and always creates a new entity instance for return.  The patch I've attached addresses this with a one-line adjustment to WsEntityProviderBase.generated.cst.

    Currently the relevant generated code for a WsEntityProvider goes something like this:

    public override Customer GetByCustomerID(int customerID)
    {
        WsProxy.Customer items = WebServiceProxy.Instance.CustomerProvider_GetByCustomerID(customerID);
        return Convert(items);
    }
    
    public static Customer Convert(WsProxy.Customer item)
    {
        Customer outItem = new Customer(); //here's the "problem"

        Convert(outItem, item); return outItem; }

    The template adjustment would generate code like this instead:

    public static Customer Convert(WsProxy.Customer item)
    {
        Customer outItem = item == null ? null : new Customer();
        Convert(outItem, item);
        return outItem;
    }
    

    Please let me know what you think.  Thanks!

     

    • Post Points: 35
  • 05-22-2008 7:57 PM In reply to

    • blake05
    • Top 25 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 351
    • Points 6,205

    Re: PATCH: WsEntityProvider returns arbitrary new item for entities that don't exist

     Hello,

    Thank you for your contribution, we have added this to our to-do list. You can check the status of this here

    Thanks

    -Blake

    Blake Niemyjski

    CodeSmith Tools, LLC Support Specialist

    Blog: http://windowscoding.com/blogs/blake/

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

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