Format:
Recent snippets matching tags of Entity
// GET: /Dog/ public ViewResult Index() { var dogs = db.PetSet.ToArray<Pet>().Where(s => s is Dog).Cast<Dog>(); return View(dogs); }
20 Views
no comments
-- generated from Context.ReportedAbuses.Where(ab => ab.EntryId == entryId).Count() > 0; exec sp_executesql N'SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[ReportedAbuses] AS [Extent1] WHERE [Extent1].[EntryId] = @p__linq__0 ) AS [GroupBy1]',N'@p__linq__0 int',@p__linq__0=3
241 Views
1 comments
/// <summary> /// Creates a Connection string from Conf.xml /// </summary> /// <param name="isEntityConnection"> /// The is Entity Connection. /// </param> /// <param name="serverName"> /// The server Name. /// </param> /// <param name="databaseName">
72 Views
no comments
[TestMethod] public void TestRenamedbContextMenu() { dbContext context = new dbContext(); // Load the first menu Menu menu = context.Menus.FirstOrDefault(); // force a change menu.ModifiedOn = DateTime.Now;
277 Views
no comments
/// <summary> /// Creates a list of a given type from all the rows in a DataReader. /// /// Note this method uses Reflection so this isn't a high performance /// operation, but it can be useful for generic data reader to entity /// conversions on the fly and with anonymous types. /// </summary> /// <typeparam name="TType"></typeparam> /// <param name="reader">An open DataReader that's in position to read</param> /// <param name="fieldsToSkip">Optional - comma delimited list of fields that you don't want to update</param>
825 Views
no comments
public class DbContextDomainService<TContext> : DomainService where TContext : DbContext, new() { private TContext _DbContext; protected TContext DbContext { get { return _DbContext ?? (_DbContext = CreateDbContext()); } }
139 Views
no comments
public partial class Entities { public void Insert<T>(T entity) where T : class { if (entity == null) throw new ArgumentNullException("entity"); // Note: changing the state to Added on a detached entity is the same as calling // Add on the DbSet. Entry(entity).State = EntityState.Added;
228 Views
no comments
#region Get entity set name public string GetEntitySetName(Type entityType) { if (entityType == null) throw new ArgumentNullException("entityType"); if (!entityType.IsSubclassOf(typeof(EntityObject))) throw new ArgumentException("Only subclasses of EntityObject are supported.", "entityType"); return GetEntitySetNameInternal(entityType);
620 Views
no comments
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>;
146 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)
1812 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)
584 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) {
527 Views
no comments
namespace Repository.EntityFramework { //Entity Class Under Test public partial class Story { public ICollection<Tag> Tags { get { if(!TagsInternal.IsLoaded)
383 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) {
364 Views
no comments
public static class A { private static Func<MyContextEntities, int, Orders> compiledGetById; static A() { compiledGetById = CompiledQuery.Compile<MyContextEntities, int, Orders>(((ctxt, orderId) => (from o in ctxt.Orders where o.Id == orderId select o).FirstOrDefault())); } public static Orders GetOrderById(int orderId)
457 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
