Skip to content

Instantly share code, notes, and snippets.

View jpolvora's full-sized avatar

Jone jpolvora

View GitHub Profile
using System;
using System.Linq;
namespace Metavision.Infra.Data
{
public interface IUnitOfWork : IDisposable
{
T Find<T>(params object[] keyValues) where T : class , new();
/// <summary>
using System;
using System.Collections.Generic;
namespace Metavision.Infra.Data
{
public interface IRepositorio : IDisposable
{
bool HasChanges { get; set; }
IUnitOfWork UnitOfWork { get; }
}
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
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>();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Metavision.Infra
{
/// <summary>
/// Service Locator simples
/// </summary>
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>
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 November 10, 2011 14:04
Utilizando Entity Framework Code First 4.1 c/ ORACLE
//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;
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 03:28
My custom implementation of DynamicDecorator from Gary H Guo
// 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