GitXplorerGitXplorer
J

FluentLinqToSql

public
8 stars
4 forks
0 issues

Commits

List of commits on branch master.
Unverified
0e9c7846c812de8574af86e5ef06b4a37dadc980

Update build script to build using .net 4 tools. Now uses SQLExpress for database tests.

JJeremySkinner committed 15 years ago
Unverified
207534883ecf726701a017b43e28304c5bfb5b2b

Update project to vs2010

JJeremySkinner committed 15 years ago
Unverified
2b65582476e8df8d591ad927f3ddb38b74e21138

Adding FindOne

JJeremySkinner committed 15 years ago
Unverified
5d34c5400243f2cf101fafc9d69c2e9812f1728d

One to many conventions

JJeremySkinner committed 15 years ago
Unverified
e6b94fc48f76f2583b3252b8263caad54d2e6ba2

Build script tweaks

JJeremySkinner committed 15 years ago
Unverified
2ee85c350e32b727fcd62197069ed219cb917dd3

Many to one conventions

JJeremySkinner committed 15 years ago

README

The README file for this repository.

Fluent Linq to Sql allows you to define mappings for Linq to Sql entities using a fluent interface rather than attributes or XML.

For discussions, documentation and binary releases please visit the CodePlex site: http://fluentlinqtosql.codeplex.com

This project was inspired by Fluent NHibernate (http://fluentnhibernate.org).

A simple example:

public class CustomerMapping : Mapping { public CustomerMapping() { Identity(customer => customer.Id); Map(customer => customer.Name); HasMany(customer => customer.Orders).OtherKey(order => order.CustomerId); } }

var mappingSource = new FluentMappingSource("Mydatabase"); mappingSource.AddFromAssemblyContaining();

var dataContext = new DataContext("connection-string", mappingSource); var customers = from c in dataContext.GetTable() select c;

Also included in this project is a Linq to Sql based ActiveRecord implementation:

public class Customer { public int Id { get; set; } //assumes public property named "Id" is PK public string Name { get; set; } //all public read/write properties auto-mapped to db cols }

//config: ActiveRecordConfiguration.Configure(cfg => { cfg.ConnectToSqlServer("(local)", "mydb", "user", "pass"); cfg.MapTypesFromAssemblyContaining(); //lots of other options... });

//usage: using(ContextScope.Begin()) { //in a web app, this can be transparent using a scope per request var customer = new Customer { Name = "Jeremy" }; customer.Save(); } //changes committed on scope disposal

using(ContextScope.Begin()) { var cust = Customer.FindById(1); //normal AR-style operations }

//testability: var fakeData = new[] { new Customer { Id = 1 }, new Customer { Id = 2 } }; using(Customer.Fake(fakeData)) { //replaces underlying data access with in-memory collection var cust = Customer.FindById(1); }

Note that if you want to run the unit tests for this project, you'll fist need to create a local SQL Server database called "FluentLinqToSql". This can be achieved by running BuildDatabase.cmd

Copyright Jeremy Skinner http://www.jeremyskinner.co.uk

Licensed under the Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.html