Skip to content

Instantly share code, notes, and snippets.

View IUnitOfWork.cs
using System;
using System.Linq;
namespace Metavision.Infra.Data
{
public interface IUnitOfWork : IDisposable
{
T Find<T>(params object[] keyValues) where T : class , new();
/// <summary>
View IRepositorio.cs
using System;
using System.Collections.Generic;
namespace Metavision.Infra.Data
{
public interface IRepositorio : IDisposable
{
bool HasChanges { get; set; }
IUnitOfWork UnitOfWork { get; }
}
View DataExtensions.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Metavision.Infra.Data;
namespace Metavision.Infra.Extensions
{
public static class DataExtensions
{
#region extensoes para Repositório
View UnitOfWorkBase.cs
using System;
using System.Collections.Generic;
using System.Data;
namespace Metavision.Infra.Data
{
public abstract class UnitOfWorkBase : IDisposable
{
protected readonly Stack<IRepositorio> StackRepositories
= new Stack<IRepositorio>();
View Container.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Metavision.Infra
{
/// <summary>
/// Service Locator simples
/// </summary>
View CodeFirstUnitOfWork.cs
using System;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using System.Linq;
namespace Metavision.Infra.Data
{
/// <summary>
View demonstracao.cs
public void DemonstrarEntityFramework()
{
var dbContext = new MyEntities(); //instancia um dbContext
var uow = new CodeFirstUnitOfWork(dbContext); //instancia um unit_of_work para coordenar repositórios
var repositorioPessoas = new Repositorio<Pessoa>(uow); //cria um novo repositório passando o unitOfWork
var repositorioEnderecos = new Repositorio<Endereco>(uow);//cria um novo repositório passando o unitOfWork
var novaPessoa = repositorioPessoas.CreateNew(); //fabrica uma nova entidade
novaPessoa.Nome = "Jone Polvora"; //seta o valor do campo Nome
@jpolvora
jpolvora / Program.cs
Created Nov 10, 2011
Utilizando Entity Framework Code First 4.1 c/ ORACLE
View Program.cs
//POST: http://silverlightrush.blogspot.com/2011/11/receita-de-bolo-para-ef-code-first-e.html
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using Oracle.DataAccess.Client;
View repositorio.sql
CREATE TABLE "PESSOAS"
( "ID" NUMBER,
"NOME" VARCHAR2(50),
CONSTRAINT "PESSOAS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE TABLE "TELEFONES"
( "ID" NUMBER NOT NULL ENABLE,
"PESSOA_ID" NUMBER NOT NULL ENABLE,
"NUMERO" VARCHAR2(10) NOT NULL ENABLE,
@jpolvora
jpolvora / DynamicDecorator.cs
Created May 17, 2012
My custom implementation of DynamicDecorator from Gary H Guo
View DynamicDecorator.cs
// Created by por Jone Polvora
// Twitter: @jpolvora
// WebSite: http://silverlightrush.blogspot.com
// Based on Dynamic Decorator / CBO Extender Project (http://www.codeproject.com/Articles/275292/Component-Based-Object-Extender)
// Depends on Impromptu-Interface (https://code.google.com/p/impromptu-interface/_
// Last Update: 21/05/2012 10:40AM GMT -04:00
// Brazil
/* USAGE EXAMPLE