CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of EntityFramework
C#
public static class ContextHelpers
{
    public static TModel Create<TModel>(this DbContext context) where TModel : class
    {
        var dbsetProperty = (from property in context.GetType().GetProperties().ToList()
                        where typeof (IDbSet<TModel>).IsAssignableFrom(property.PropertyType)
                        select property).Single();
 
        var dbset = dbsetProperty.GetValue(context, null) as IDbSet<TModel>;
by John Nelson   March 17, 2011 @ 8:58am
111 Views
no comments
 
<#
//       Created by Dan Wahlin - http://www.thewahlingroup.com
//     Title: T4 Metadata and Data Annotations template
//       Usage: Generates the initial "buddy" classes to handle data validation across multiple frameworks
//       Description: I got tired of writing my initial "buddy" classes by hand once my EF model was created. This template
//                    handles generating all the classes and generates the primitive and navigation properties. It also
//                    decorates the properties with the [Required] and [StringLength] attributes as appropriate. Once the
//                    template generates the code you can copy it to a new file and make all the tweaks you want to support
//                    custom data annotations.
//       License: UIFAYW - Use it for anything you want (free or commercial)
by Dan Wahlin   February 20, 2011 @ 9:27am
1384 Views
no comments
 
C#
public interface IQuery<TResult>
{
    //Execute method that accepts an ObjectContext and returns a TResult
    TResult Execute(EntityContext context);
}
 
public abstract class QueryBase<TResult> : IQuery<TResult>
{
    //userCompiled parameter to decide whether to use compiled query or plain one
    protected QueryBase(bool useCompiled)
by Muhammad Mosa   September 05, 2009 @ 7:08pm
523 Views
no comments
 
C#
//Class Under Test
public class CategoryRepository : BaseRepository<Category>
{
    //EntityContainer is an ObjectContext
    public CategoryRepository(EntityContainer context)
        : base(context){}
 
    //Method Under Test
    public Category FindById(Guid id)
    {
by Muhammad Mosa   September 02, 2009 @ 10:58am
480 Views
no comments
 
C#
namespace Repository.EntityFramework
{
    //Entity Class Under Test
    public partial class Story
    {
        public ICollection<Tag> Tags
        {
            get
            {
                if(!TagsInternal.IsLoaded)
by Muhammad Mosa   September 01, 2009 @ 2:38pm
354 Views
no comments
 
C#
//Class under test code snippet
public class CategoryRepository : BaseRepository<Category>
{
        //EntityContainer class is an ObjectContext of Entity Framework
        public CategoryRepository(EntityContainer context)
            : base(context)
        {
        }
        public override void Add(Category category)
        {
by Muhammad Mosa   August 31, 2009 @ 1:55pm
333 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate