using System.Linq.Expressions;
public static void Main()
var customerSqlString = GetPropertyName(() => Dbo.Customer);
Console.WriteLine(customerSqlString);
public static CustomerTable Customer = new CustomerTable();
public class CustomerTable
public string TableName { get; set; }
public static string GetPropertyName<T>(Expression<Func<T>> propertyLambda)
var me = propertyLambda.Body as MemberExpression;
throw new ArgumentNullException("MemberExpression");
var schema = string.Empty;
if (me.Type.DeclaringType != null)
schema = me.Type.DeclaringType.Name;
throw new ArgumentException("You must pass a lambda of the form: " +
"'() => Class.Property' or '() => object.Property'");
return string.Format("[{0}].[{1}]", schema.ToLower(), me.Member.Name);