Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Created January 6, 2012 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeimpossible/1571716 to your computer and use it in GitHub Desktop.
Save codeimpossible/1571716 to your computer and use it in GitHub Desktop.
Massive Fluently rough draft
using System;
using System.Dynamic;
using Massive;
namespace MassiveFluently.Expressions {
public class All {}
public class First {}
public class Last {}
}
namespace MassiveFluently {
///<example>
/// MassiveFluently.Defaults( m => m.PrimaryKey = "Id" );
///
/// new MassiveFluently()
/// .ConnectTo("MyConnection")
/// .ProductsTable
/// .all();
///
/// OR
///
/// var items = (All) new MassiveFluently().ConnectTo("SomeConnection").Products;
///</example>
public class MassiveFluently {
private static Action<DynamicModel> _defaultSettings = (m) => m.PrimaryKey = "Id";
   
internal string _connectionStringName = null;
   private MassiveFluently(string connectionStringName) {
       _connectionStringName = connectionStringName;
   }
public static MassiveFluently Defaults( Action<DynamicModel> setDefaults ) {
_defaultSettings = setDefaults;
}
   public static MassiveFluently ConnectTo(string connectionStringName) {
       return new MassiveFluently(connectionStringName);
   }
   public class MassiveContextBase : DynamicModel {
      internal MassiveContextBase() {
MassiveFluently_defaultSettings(this);
base(MassiveFluently._connectionStringName)
}
internal MassiveContextBase(string tableName) : this() {
TableName = this;
}
internal MassiveContextBase(string connectionStringName, string tableName, string primaryKey) :
           base (connectionStringName){
           TableName = tableName;
           PrimaryKey = primaryKey;
       }
public override bool TryConvert ( ConvertBinder binder, out object result) {
if(binder.Type == typeof(MassiveFluently.Expressions.All) ) {
result = this.All();
}
if(binder.Type == typeof(MassiveFluently.Expressions.First)) {
result = this.First();
}
if(binder.Type == typeof(MassiveFluently.Expressions.Last)) {
result = this.Last();
}
base.TryConvert(binder,out result);
}
   }
   public static DynamicModel GetContext(string tableName, string primaryKeyColumn) {
       return new MassiveContextBase(_connectionStringName, tableName, primaryKeyColumn);
   }
public override bool TryGetMember(GetMemberBinder binder, out object result) {
var table = binder.name;
if(binder.name.EndsWith("Table")) {
table = binder.name.Replace("Table", "");
}
result = new MassiveContextBase(table);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment