Tuesday, 11 December 2012

LazyloadingEnable and ProxyCreationEnabled?


yes, lazyloadingEnable and ProxyCreationEnabled are by default true. yes using lazyloading should be true for referencing the reference tables.
so

            this.Configuration.LazyLoadingEnabled = true;
           this.Configuration.ProxyCreationEnabled = true;
           
both must be enabled true otherwise gives error. bydefault LazyLoadingEnabled is true because of all the related entities are loaded automatically.

           
   var t = context.emps.Find(4);
as well

if any case : 

  this.Configuration.ProxyCreationEnabled = false

                also we can load the relavent entities using 
   var t = context.emps.Find(4);
   context.Entry(t).Reference("Dept").Load();  // Proxy Creation
  or
  context.Entry(t).Reference(t=>t.Dept).Load(); // here Dept can't be a non-generic collection.




     var s  =context.emps.Local;
    context.emps.Add(new Employee { Ename = "rani", EPhone = "7478", EmpDept = 2 });
    context.SaveChanges();
             
using local properties we can able to track the changes at client when we add, delete, ...from a collection why because Local is Property which is of

ObservableCollection<TEntity> Local { get; }.


   var s  =context.emps.Local;  // Local return type is ObservableCollection. so we can easily track the changes of a collection at dynamically.

  context.emps.Add(new Employee { Ename = "rani", EPhone = "7478", EmpDept = 2 });  //1

               var  d = context.emps.FirstOrDefault(k => k.Ename == "narayan");
               d.Ename = "prasads";                                                //2
IEnumerable<DbEntityEntry<Employee>> change =context.ChangeTracker.Entries<Employee>();

               IEnumerator<DbEntityEntry<Employee>> ier = change.GetEnumerator();
               IEnumerable<string> currentval = new List<string>();
               IEnumerable<string> original = new List<string>();

               while (ier.MoveNext())
               {
                    currentval=ier.Current.CurrentValues.PropertyNames;
                    original=ier.Current.OriginalValues.PropertyNames;

               }

immediate window
change.count()
2
context.emps.Local[0]
{EFCodeFirstDemo.Employee}
    Dept: null
    Eid: 0
    EmpDept: 2
    Ename: "rani"
    EPhone: "7478"

No comments:

Post a Comment