Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> May I assign entity value to new record
 

Pages: 1
LLBLGen Pro Runtime Framework
May I assign entity value to new record
Page:1/1 

  Print all messages in this thread  
Poster Message
nopchan
User



Location:

Joined on:
30-Apr-2005 02:19:03
Posted:
56 posts
# Posted on: 16-Jun-2008 12:34:26.  

adapter = new DataModel.DatabaseSpecific.DataAccessAdapter(SetConnectionString);
RemoteAdapter= new DataModel.DatabaseSpecific.DataAccessAdapter(SetRemoteServerConnectionString);


NewApnameEntity = new ApnameEntity(ShowGljourEntity.ApnameCode.ToString().Trim());
adapter.FetchEntity(NewApnameEntity);
if (NewApnameEntity.IsNew)
{
     ShowApnameEntity = new ApnameEntity(ShowGljourEntity.ApnameCode.ToString().Trim());
     RemoteAdapter.FetchEntity(ShowApnameEntity);
     if (!ShowApnameEntity.IsNew)
     {
         NewApnameEntity = ShowApnameEntity;
         adapter.SaveEntity(NewApnameEntity);

     }

}

I can not save NewApnameEntity to my database.

  Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
385 posts
# Posted on: 16-Jun-2008 16:54:59.  
You must synchronize the entity yourself, i.e. you should copy the values of the entity manually (maybe overriding the Equals method) and then saving the entity with your local adapter. See other threads regarding "Copying Entities".

gansodesoya  Top
nopchan
User



Location:

Joined on:
30-Apr-2005 02:19:03
Posted:
56 posts
# Posted on: 17-Jun-2008 03:56:23.  
Code:

adapter = new DataModel.DatabaseSpecific.DataAccessAdapter(SetConnectionString);
RemoteAdapter= new DataModel.DatabaseSpecific.DataAccessAdapter(SetRemoteServerConnectionString);
private ApnameEntity ShowApnameEntity;
private ApnameEntity NewApnameEntity;

adapter.StartTransaction(IsolationLevel.Serializable, "AddData");

NewApnameEntity = new ApnameEntity(ShowGljourEntity.ApnameCode.ToString().Trim());
adapter.FetchEntity(NewApnameEntity);
if (NewApnameEntity.IsNew)
{
     ShowApnameEntity = new ApnameEntity(ShowGljourEntity.ApnameCode.ToString().Trim());
     RemoteAdapter.FetchEntity(ShowApnameEntity);
     if (!ShowApnameEntity.IsNew)
     {
         CopyFieldsInEntity(ShowApnameEntity, NewApnameEntity);
        
         adapter.SaveEntity(NewApnameEntity);
         adapter.Commit();
         ApnameEntity New2ApnameEntity = new ApnameEntity (ShowGljourEntity.ApnameCode.ToString().Trim());
         adapter.FetchEntity(New2ApnameEntity );
         if (New2ApnameEntity .IsNew)
         {
                 Console.Write("Not Found Data");

         }
            else
             {
                     Console.Write("Found Data");

            }
     }

}


private void CopyFieldsInEntity(EntityBase2 srcEntity, EntityBase2 destEntity)
        {
            if (!srcEntity.IsNew)
                destEntity.Fields = (IEntityFields2)((EntityFields2)srcEntity.Fields).Clone();

            if (srcEntity.IsNew || srcEntity.IsDirty)
            {
                foreach (EntityField field in (EntityFields2)srcEntity.Fields)
                {
                    if (field.IsChanged)
                        destEntity.SetNewFieldValue(field.FieldIndex, field.CurrentValue);
                }
            }
        }



I am not found data. I can not save data but code is not error.

Remark . run on LLBLGenPro 2.6 with Sqlserver 2005 std.


  Top
nopchan
User



Location:

Joined on:
30-Apr-2005 02:19:03
Posted:
56 posts
# Posted on: 17-Jun-2008 04:40:32.  
I change new code then it's work ok.

Code:

private void CopyFieldsInEntity(EntityBase2 srcEntity, EntityBase2 destEntity)
        {
            if (!srcEntity.IsNew)
            {
                
                foreach (EntityField2 field in (EntityFields2)srcEntity.Fields)
                {
                    if ( !field.IsReadOnly)
                        destEntity.SetNewFieldValue(field.FieldIndex, field.CurrentValue);
                }
            }
            if (srcEntity.IsNew || srcEntity.IsDirty)
            {
                foreach (EntityField2 field in (EntityFields2)srcEntity.Fields)
                {
                    if (field.IsChanged && !field.IsReadOnly)
                        destEntity.SetNewFieldValue(field.FieldIndex, field.CurrentValue);
                }
            }
        }
        


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.