using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace EmployeeProject
{
// model
[TableAttribute(Name = "dbo.ADEmployee")] // name = database table
public class Employee
{
[ColumnAttribute(Name = "displayName")] // name = database column name
public string DisplayName { get; set; }
[ColumnAttribute(Name = "objectGUID")]
public Guid GUID { get; set; }
}
// context
public class EmployeeDataContext : DataContext
{
public EmployeeDataContext() : base("YOUR CONNECTION STRING") { }
public Table Employees
{
get { return this.GetTable(); }
}
}
// sample repository
public class EmployeeRepository
{
public IEnumerable GetAll()
{
var db = new EmployeeContext();
return db.Employees.ToList();
}
}
}
.NET: Custom DataContext
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment