Format:
Recent snippets matching tags of EntityFramework
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>;
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)
1384 Views
no comments
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)
523 Views
no comments
//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) {
480 Views
no comments
namespace Repository.EntityFramework { //Entity Class Under Test public partial class Story { public ICollection<Tag> Tags { get { if(!TagsInternal.IsLoaded)
354 Views
no comments
//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) {
333 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
