Let say I have these two tables
A list of accounts
CREATE TABLE [dbo].[Accounts](
[Id] [uniqueidentifier] NOT NULL,
[CreatedDateTime] [datetime] NOT NULL,
[Active] [bit] NOT NULL,
[CompanyName] nvarchar NOT NULL,
[BranchName] nvarchar NULL,
[OfficeAddressId] [uniqueidentifier] NULL,
[CorrespondenceAddressId] [uniqueidentifier] NULL,
[InvoiceAddressId] [uniqueidentifier] NULL,
[SalesContactId] [uniqueidentifier] NULL,
[InvoiceContactId] [uniqueidentifier] NULL
)
And a list of addresses
CREATE TABLE [dbo].[Addresses](
[Id] [uniqueidentifier] NOT NULL,
[CreatedDateTime] [datetime] NOT NULL,
[Active] [bit] NOT NULL,
[BuildingName] nvarchar NULL,
[HouseNumber] nvarchar NULL,
[Housename] nvarchar NULL,
[Street] nvarchar NOT NULL,
[District] nvarchar NULL,
[Town] nvarchar NULL,
[CountyId] [uniqueidentifier] NULL,
[CountryId] [uniqueidentifier] NULL
}
I want to create a new account with 3 different addresses (OfficeAddressId,CorrespondenceAddressId, InvoiceAddressId) in one call to the web service.
One way I could do it is to do the following
[WebMethod]
public Guid SaveAddress(AddressEntity toSave)
{
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
Guid addressguid = System.Guid.NewGuid();
toSave.Id = addressguid;
adapter.SaveEntity(toSave);
return addressguid;
}
}
}
I would create the 3 different addresses seperately and then populate the main Account entity with thier ID's
But it sounds much to to pass the account entity with all related objects attached. How can I do that?
Thanks very much