Projection to a DataTable

Posts   
 
    
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 25-Jul-2008 01:58:56   

I'm attempting to project an EntityCollection into a DataTable and I'm run into some weirdness that I can't figure out. Basically, when I project to a DataTable, I get the correct number of rows returned, but there are no values in any of the cells.

I'm running in VS2008 against AdventureWorks on SQL Server 2005.

Any and all help is greatly appreciated.

Thanks,

Jeremiah

Here's the code I'm using:


EntityCollection<SalesOrderHeaderEntity> orders = new EntityCollection<SalesOrderHeaderEntity>();

using (DataAccessAdapter _adapter = new DataAccessAdapter())
{
    IRelationPredicateBucket bucket = new RelationPredicateBucket();
    bucket.Relations.Add(SalesOrderHeaderEntity.Relations.ContactEntityUsingContactId);
    bucket.Relations.Add(SalesOrderHeaderEntity.Relations.CreditCardEntityUsingCreditCardId);
    bucket.Relations.Add(SalesOrderHeaderEntity.Relations.SalesOrderDetailEntityUsingSalesOrderId);
    bucket.Relations.Add(SalesOrderDetailEntity.Relations.ProductEntityUsingProductId);
    bucket.PredicateExpression.Add(ContactFields.FirstName == FirstName.Text.Trim());
    bucket.PredicateExpression.Add(ContactFields.LastName == LastName.Text.Trim());

    IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.SalesOrderHeaderEntity);
    prefetch.Add(SalesOrderHeaderEntity.PrefetchPathContact);
    prefetch.Add(SalesOrderHeaderEntity.PrefetchPathCreditCard);
    prefetch.Add(SalesOrderHeaderEntity.PrefetchPathSalesOrderDetail).SubPath.Add(SalesOrderDetailEntity.PrefetchPathProduct);

    _adapter.FetchEntityCollection(orders, bucket, prefetch);

    llblDataSource.PrefetchPathToUse = prefetch;
}

List<IEntityPropertyProjector> projection = new List<IEntityPropertyProjector>();

projection.Add(new EntityPropertyProjector(ContactFields.FirstName, "FirstName"));
projection.Add(new EntityPropertyProjector(ContactFields.LastName, "LastName"));
projection.Add(new EntityPropertyProjector(CreditCardFields.CardNumber, "CardNumber"));
projection.Add(new EntityPropertyProjector(CreditCardFields.CardType, "CardType"));
projection.Add(new EntityPropertyProjector(SalesOrderHeaderFields.PurchaseOrderNumber, "PONumber"));
projection.Add(new EntityPropertyProjector(SalesOrderDetailFields.OrderQty, "Qty"));
projection.Add(new EntityPropertyProjector(ProductFields.Name, "ProductName"));

EntityView2<SalesOrderHeaderEntity> headerView = orders.DefaultView;
DataTable orderHeaders = new DataTable();

headerView.CreateProjection(projection, orderHeaders);



OrderGrid.DataSource = orderHeaders;
OrderGrid.DataBind();

peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 25-Jul-2008 03:54:33   

Ignore me, please. I just remember that I posted about this two years ago and the answer hasn't changed: a TypedList is the way to go.