using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;


namespace plugin1
{
    public class Class1 :IPlugin
    {


        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

       
            new_teston test = (new_teston)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
        
            //QueryExpression querry = new QueryExpression(new_testto.EntityLogicalName);
            //querry.ColumnSet = new ColumnSet(true);
            //EntityCollection test1 = service.RetrieveMultiple(querry);
         
            //int count = test1.Entities.Count;

            //new_testto test11 = new new_testto();

            //for (int i = 0; i <= count; i++)
        
            new_testto tes = new new_testto();
            tes.new_name = "test";
            tes.new_singlelineto = test.new_singleline;
         
            service.Create(tes);

        }
    }
}
















SOURCE : JUST2CODE.COM