Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active December 13, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4959801 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4959801 to your computer and use it in GitHub Desktop.
ORMS: NPersist example
[ClassMap(Table = "People")]
public class Person
{
[PropertyMap(Columns = "EmployeeId", IsIdentity = true, IsAssignedBySource = true)]
public virtual Guid Id { get; set; }
[PropertyMap(Columns = "Name")]
public virtual string Name { get; set; }
[PropertyMap(Columns = "Email")]
public virtual string Email { get; set; }
}
// These are required in your assemblyinfo
[assembly: DomainMap(Source = "HelloWorldSource")]
[assembly: SourceMap(Compute = true, Name = "HelloWorldSource")]
public class PersonManager
{
public static void Example()
{
using (IContext context = GetContext())
{
// app.config/web.config settings would be used in GetContext()
Person person = (Person)context.CreateObject(typeof(Person));
person.Id = Guid.NewGuid(); // This might not be needed
person.Name = "John";
person.Email = "john@aol.com";
context.Commit();
Person person = (Person)context.GetObjectById(Guid.NewGuid()); // this would be a proper guid
IList<Person> list = context.GetObjects(typeof(Employee));
// Filtered loading, basically SQL
NPathQuery query = new NPathQuery("Select * from Person Where Name=?", typeof(Person));
query.Parameters.Add(new QueryParameter(DbType.AnsiString, "John"));
list = context.GetObjectsByNPath(query);
}
}
private IContext GetContext()
{
IContext context = new Context(this.GetType().Assembly);
context.SetConnectionString("server=(local);uid=xxx;pwd=xxx;database=yourdb;");
return context;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment