linq to entities - Entity Framework - how to save entity without saving related objects -


In my unit framework, I have three related entities, such as' clients ',' Client Address 'and' LookupAddressType '" LookupAddressType " A master class specifies the type of available address type, like business address, residential addresses, etc. LookupAddresstype and dependent clients on> ClientAddress . Savings Client unit with relevant ClientAddress data, I'm getting the following error.

"PRIMARY KEY constraint violation 'PK_LookupAddressType'. Can not insert duplicate key in object 'dbo.LookupAddressType'. The statement has been terminated.

I insert not need LookupAddressType. I just need to be put in the relevant lookupAddressTypeId client Atader unit.

saving code like this:

 < Code> Add (Client); _objectContext.SaveChanges ();   

How can I do this

Without the Load Code Che :?

  private void LoadClientDetails (EFEntities.Client _Client) {EFEntities.LookupClientStatu clientStatus; var clientAddressList = new List of & lt; & gt ClientAddress; (); if (_Client == null) {return;} // Assign customer object _Client.ClientName = rtxtName.Text to data; _Client.Alias ​​= rtxtAlias.Text; _Client.ClientCode = Int32.Parse (rtxtClientCode.Text); _Client.TaxPa YerID = rtxtTaxPayerId.Text; if (rcboStatus.SelectedIndex = 0!) {clientStatus = new EFEntities.LookupClientStatu {ClientStatusID = (GUID) (rcboStatus.SelectedValue), ClientStatusDescription = rcboStatus.Text}; _Client.LookupClientStatu = ClientStatus; } //_Client.Modified = EnvironmentClass.ModifiedUserInstance.Id; _Client.EffectiveDate = rdtEffectiveDate.Value; If (rdtExpDate.Value! = RdtExpDate.MinDate) {_Client.ExpirationDate = rdtExpDate.Value; } And {_Client.ExpirationDate = null; } _Client.StartDate = DateTime.Now; EFEntities.ClientAddress ClientAuthor = Null; // Iesi.Collections.Generic.ISet & lt; ClientAddress & gt; Client address = new hashset & lt; Client address & gt; (); Foreign Currency (diverse cadre in _clientController.client.ClientAddresses) {clientAddress = cAddress; break; } If (Client Address == blank) {clientAddress = New EFEntities.ClientAddress (); } ClientAddress.Address1 = rtxtClientAdd1.Text; Client Addresses Address2 = rtxtClientAdd2.Text; Client Addresses Address 3 = RTX ClientAud 3. Text; // Address Type Description (rcboClientAddType.SelectedIndex! = -1) {clientAddress.LookupAddressType = New EFEntities.LookupAddressType {AddressType = (Guid) (address: TypeTypeDescription = rcboClientAddType.Text}; //clientAddress.AddressType.Id = Convert. ToByte (rcboClientAddType.SelectedValue); } ClientAddress.City = rtxtClientCity.Text; ClientAddress.Client = _Client;   

\

  _Client.ClientAddresses.Add (client address); } 

Well, I did it in the following lines of code to work. / P>

  if (rcboClientAddType.SelectedIndex! = -1) {clientAddress.LookupAddressType = New EFEntities.LookupAddressType {AddressTypeID = (Guid) (rcboClientAddType.SelectedValue), AddressTypeDescription = rcboClientAddType.Text}; //clientAddress.AddressType.Id = Convert. ToByte (rcboClientAddType.SelectedValue); }   

I have changed the above code

  if (rcboClientAddType.SelectedIndex! = -1) {//clientAddress.LookupAddressType = new EFEntities. LookupAddressType // {// AddressTypeID = (Guid) (rcboClientAddType.SelectedValue), // AddressTypeDiscription = rcboClientAddType.Text //}; Client Addresses Address Type AIDI = (Guide) (RCBClientEdit. Value selected); }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -