Posts Tagged ‘msdn’


I was recently working on some migration of Ado.Net to EF 3.5 (not to EF4, due to some constraints). It was quite challenging for me to find out how to implement the Eager loading in EF3.5.

So i thought of sharing the code with anyone who needs it

public static class EFExtensions
{
	public static TSource LoadAll<TSource>(this TSource source) where TSource : EntityObject
	{
		if (source != null)
		{
			Type type = source.GetType();
			foreach (var property in type.GetProperties().Where(property => typeof(EntityReference).IsAssignableFrom(property.PropertyType)))
			{
				((EntityReference)type.InvokeMember(property.Name, BindingFlags.GetProperty, null, source, null)).Load();
			}

			foreach (var property in type.GetProperties().Where(property => typeof(EntityObject).IsAssignableFrom(property.PropertyType)))
			{
				var test = (EntityObject)type.InvokeMember(property.Name, BindingFlags.GetProperty, null, source, null);
				LazyLoad(test);
			}
		}
		return source;
	}

	public static List<TSource> LoadAll<TSource>(this IQueryable<TSource> source)
	{
		foreach (var entity in source)
		{
			if (!(entity is EntityObject)) continue;
			Type type = entity.GetType();
			foreach (var property in type.GetProperties().Where(property => typeof(EntityReference).IsAssignableFrom(property.PropertyType)))
			{
				((EntityReference)type.InvokeMember(property.Name, BindingFlags.GetProperty, null, entity, null)).Load();
			}
			foreach (var property in type.GetProperties().Where(property => typeof(EntityObject).IsAssignableFrom(property.PropertyType)))
			{
				LazyLoad((EntityObject)type.InvokeMember(property.Name, BindingFlags.GetProperty, null, entity, null));
			}
		}
		return source.ToList();
	}
}

Usage:

var employees = (from i in tm.Schema.company_employee
                 where i.Company.ID == id
                 select i).LoadAll();

or

var employee = from i in tm.Schema.Employees
               where i.ID == id
               select i;

var oneEmployee = em.First().LoadAll().GetEmployeeObject();

The above seems to be working fine but feel free to test it or enhance it further. 🙂


I was stumbling across the msdn and blogs to find a proper way of using Lambda with ThreadPools but could not find so.

After spending few hours found a way to do it properly. Here it goes:

(more…)


I started using quite sometime back the MVVM pattern with WPF apps and seems its great. The pattern can give so much flexibility to the developer and on top of that many of the small tasks are handled by the framework once you are ready to go.

Just to describe at a high-level about the pattern:

The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of the Presentation Model design pattern introduced by Martin Fowler. Largely based on the Model-view-controller pattern (MVC), MVVM is targeted at modern UI development platforms (Windows Presentation Foundation and Silverlight) in which there is a UX developer who has different requirements than a more “traditional” developer (i.e. oriented toward business logic and back end development).

More information can be found at the MSDN page:


Varun Rai (@rai_varun) has shared a Tweet with you:  “rai_varun: #Microsoft to release VB6 as open source http://t.co/POyS0tD” –http://twitter.com/rai_varun/status/71562304654819328