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;
}
Patch can be found here
(http://community.codesmithtools.com/forums/p/8333/30634.aspx#30634)
What version of .netTiers and CodeSmith are you using?
2.2
Please use labels and text to provide additional information.
Original issue reported on code.google.com by bniemyjski on 23 May 2008 at 12:56
Original issue reported on code.google.com by
bniemyjski
on 23 May 2008 at 12:56