Hi Wade,
Wade wrote:
I don't think FetchNewEntity is correct for the case I mention. In the documentation it is used with either a Related Entity or a Inherited Entity (PolyMorphic).
As a matter of fact, you also can use **FetchNewEntity **to perform the query you are looking for.
See, here is an example (I want to fetch the first customer that fit my criteria):
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(CustomerFields.Country == "USA");
CustomerEntity theCustomer = new CustomerEntity();
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
theCustomer = (CustomerEntity) adapter.FetchNewEntity(new CustomerEntityFactory(), filter);
}
Here is the generated code for that fetch:
SELECT TOP 1 [Northwind].[dbo].[Customers].[CustomerID] AS [CustomerId], [Northwind].[dbo].[Customers].[CompanyName], [Northwind].[dbo].[Customers].[ContactName], [Northwind].[dbo].[Customers].[ContactTitle], [Northwind].[dbo].[Customers].[Address], [Northwind].[dbo].[Customers].[City], [Northwind].[dbo].[Customers].[Region], [Northwind].[dbo].[Customers].[PostalCode], [Northwind].[dbo].[Customers].[Country], [Northwind].[dbo].[Customers].[Phone], [Northwind].[dbo].[Customers].[Fax] FROM [Northwind].[dbo].[Customers] WHERE ( ( [Northwind].[dbo].[Customers].[Country] = @Country1))
Parameter: @Country1 : String. Length: 15. Precision: 0. Scale: 0. Direction: Input. Value: "USA".
Hope helpful