Entity replication

Posts   
 
    
Chad
User
Posts: 5
Joined: 12-Oct-2004
# Posted on: 13-Oct-2004 04:43:09   

Hi there all.

Another VERY newbie on board simple_smile .

I need to replicate an entity.

A bit of background: Client app, Remoted class with host, Original Northwind sql DB, an empty Northwind2 with same schema as the original Northwind.

1) Client app connects to remoted class that creates an Entity object from the original Northwind database and passes it back as an IEntity2; 2) Modify some entity properties….(see below) 3) Client app create a new DataAccessAdapter pointing to Northwind2 and tries to save the entity.

I’ve tried but I must be missing something.

Cheers,

Some source code:

My remoted class method.

public IEntity2 GetCustomer(string strCustomerID)
{
  IEntity2 en = new CustomersEntity(strCustomerID);
  DataAccessAdapter da = new DataAccessAdapter();
  IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.CustomersEntity);
  prefetch.Add(CustomersEntity.PrefetchPathOrders).SubPath.Add(OrdersEntity.PrefetchPathProducts);
  da.FetchEntity(en,prefetch);
  return en;
}

In the client:

private void button1_Click(object sender, System.EventArgs e)
{
    IEntity2 en = userControl.GetCustomer("ANTON");
    DataAccessAdapter da = new DataAccessAdapter(); 

    //en.IsNew = true; // :-( does not work, no sql activity on nw2

    //en.Fields.State = SD.LLBLGen.Pro.ORMSupportClasses.EntityState.New; // :-( does not work, no sql activity on nw2

    en.PrimaryKeyFields[0] = "ANT22"; //still luck either
    da.SaveEntity(en);
}

App.config (snip)

<appSettings>
        <add key="Main.ConnectionString" value="data source=localhost;initial catalog=Northwind2;integrated security=SSPI;persist security info=False;packet size=4096"/>
        <add key="CatalogNameUsageSetting" value="1"/>
        <add key="CatalogNameToUse" value="Northwind2" />
</appSettings>
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Oct-2004 10:58:40   

Set IsNew to true, this will make the database action an insert. Then, mark all fields as changed and set the Fields IsDirty flag.

en.Fields.IsDirty=true; for(int i=0;i<en.Fields.Count;i++) { en.Fields.IsChanged=true; }

then save the entity simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Chad
User
Posts: 5
Joined: 12-Oct-2004
# Posted on: 14-Oct-2004 01:29:05   

Dude, you rock.