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 Entity
C#
// GET: /Dog/
public ViewResult Index()
{
  var dogs = db.PetSet.ToArray<Pet>().Where(s => s is Dog).Cast<Dog>();
  return View(dogs);
}
by Alessandro Fabozzi (google)   April 07, 2012 @ 11:33pm
20 Views
no comments
 
SQL
-- 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
 
by Rick Strahl   March 29, 2012 @ 6:59pm
241 Views
1 comments
 
C#
/// <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">
by Sigurður Bjarnason   October 10, 2011 @ 8:53am
72 Views
no comments
 
C#
 [TestMethod]
 public void TestRenamedbContextMenu()
 {
     dbContext context = new dbContext();
 
     // Load the first menu
     Menu menu = context.Menus.FirstOrDefault();
 
     // force a change
     menu.ModifiedOn = DateTime.Now;
by Rick Strahl   September 27, 2011 @ 4:43am
277 Views
no comments
 
C#
/// <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>
by Rick Strahl   September 23, 2011 @ 3:26pm
825 Views
no comments
 
C#
public class DbContextDomainService<TContext> : DomainService where TContext : DbContext, new()
{
  private TContext _DbContext;
  protected TContext DbContext
  {
    get
    {              
      return _DbContext ?? (_DbContext = CreateDbContext());
    }
  }
by Shimmy Weitzhandler   May 27, 2011 @ 3:28am
139 Views
no comments
 
C#
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;
by Shimmy Weitzhandler   May 27, 2011 @ 3:24am
228 Views
no comments
 
C#
#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);
by Shimmy Weitzhandler   May 18, 2011 @ 8:13pm
620 Views
no comments
 
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
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)
by Dan Wahlin   February 20, 2011 @ 9:27am
1812 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
584 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
527 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
383 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
364 Views
no comments
 
C#
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
 
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