Development – Leet 4 Life

Software Development Code Samples and More

Skip to: Content | Sidebar | Footer

Category: Entity Framework

Convert One Entity Object to A Similar Entity Object

30 April, 2012 | C#. NET, Entity Framework | By: Michael Merrell

Not too long ago I came across the need to be able to convert one entity object to another similar entity object for use in display purposes and mapping. Even though these two objects were nearly identical they had over two hundred fields in them so writing a method to simply set properties equal to each other would have created a huge method and a higher chance of error. Using reflection I created a nice little thinned down method that will take in your source object, the output object type, and a reference to the instantiated output object. Then using [Read More…]

Randomizing Results of a Data Query in T-SQL and the Entity Framework

9 April, 2012 | C#. NET, Entity Framework, T-SQL | By: Michael Merrell

There are many scenarios where you may need to randomize the results of a query that is pulling data out of your database.  When you are able to do this using straight T-SQL the statement is simple and easy.  All you have to do to get random ordered results using T-SQL is add the following order by clause to the end of your statement. The issue comes into play when you need to do this inside of the Entity Framework when pulling form LINQ to SQL. While there are several different ways you can do this when you are using LINQ to [Read More…]