Skip to content

Instantly share code, notes, and snippets.

@ti-ka
Last active June 22, 2016 20:03
Show Gist options
  • Save ti-ka/9533a8b63fd60510766e15f0fb82f3e9 to your computer and use it in GitHub Desktop.
Save ti-ka/9533a8b63fd60510766e15f0fb82f3e9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PetaPoco;
namespace Prognose.Web.Models
{
[PrimaryKey("SVS")]
public class Accounting : DbContext<Accounting>
{
public int SVS { get; set; }
public int ClientId { get; set; }
public string ClientReference { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? DueDate { get; set; }
public double Fee { get; set; }
public string CreditCard { get; set; }
public string PropertyType { get; set; }
[ResultColumn] public Client Client { get { return GetClient(ClientId); } set { SetClient(value); } }
#region Private Fields to save information to avoid Frequent DB Calls
private Client _client { get; set; }
#endregion
#region Getters & Setters
public Client GetClient(int Id)
{
if (_client == null)
return Client.Get(Id);
return _client;
}
public void SetClient(Client client)
{
_client = client;
ClientId = client.Id;
}
#endregion
public override void Save()
{
Client.Save();
ClientId = Client.Id;
base.Save();
}
}
public class Client : DbContext<Client>
{
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<Client> GetClients()
{
return GetAll();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment