public class Person
{
public bool FirstNameIsActive { get; set; }
public bool SecondNameIsActive { get; set; }
}
public List<Person> list = new List<Person>() {
new Person() {
FirstNameIsActive = true,
SecondNameIsActive = false
},
new Person() {
FirstNameIsActive = false,
SecondNameIsActive = true
}
};
private IQueryable<Person> Filter(PropertyInfo property, bool isActive)
{
IQueryable<Person> queryableData = list.AsQueryable<Person>();
//create input parameter
ParameterExpression inputParam = Expression.Parameter(typeof(Person));
//left contition
Expression left = Expression.Property(inputParam, property);
//right condition
Expression right = Expression.Constant(isActive, typeof(bool));
//equals
Expression e1 = Expression.Equal(left, right);
//create call
MethodCallExpression whereCallExpression = Expression.Call(
typeof(Queryable),
"Where",
new Type[] { queryableData.ElementType },
queryableData.Expression,
Expression.Lambda<Func<Person, bool>>(e1, new ParameterExpression[] { inputParam }));
//execute and return
return queryableData.Provider.CreateQuery<Person>(whereCallExpression);
}
private void test()
{
Filter(typeof(Person).GetProperty("FirstNameIsActive"), true);
Filter(typeof(Person).GetProperty("SecondNameIsActive"), true);
}
//property selector
Func<Person, Boolean> propertySelector = person => person.FirstNameIsActive;
//your predicate
Func<Person, Boolean> predicate = person => propertySelector(person) == true;
//new person with true, false properties.
Person p = new Person() {FirstNameIsActive = true,SecondNameIsActive = false};
Console.WriteLine(predicate(p).ToString()); //prints true
//change the property selector
propertySelector = person => person.SecondNameIsActive;
//now the predicate uses the new property selector
Console.WriteLine(predicate(p).ToString()); //prints false
public class Book
{
public string Title {get;set;}
public string Author {get;set;}
}
public class BookController : Controller
{
[HttpPost]
public ActionResult Create(Book model, IEnumerable<HttpPostedFileBase> fileUpload)
{
throw new NotImplementedException();
}
}
@using (Html.BeginForm("Create", "Book", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.EditorFor(m => m)
<input type="file" name="fileUpload[0]" /><br />
<input type="file" name="fileUpload[1]" /><br />
<input type="file" name="fileUpload[2]" /><br />
<input type="submit" name="Submit" id="SubmitMultiply" value="Upload" />
}
<input type="file" name="fileUpload[0]" />
IEnumerable<HttpPostedFileBase> fileUpload
using (WdmEntities context = new WdmEntities())
{
//get object models from context
ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
//get all full names types from object model
var fullNameTypes = objContext.MetadataWorkspace.GetItems<EntityType>(DataSpace.OSpace);
///////////////////
var conStr = objContext.Connection.ConnectionString;
var connection = new EntityConnection(conStr);
var workspace = connection.GetMetadataWorkspace();
var entitySets = workspace.GetItems<EntityContainer>(DataSpace.SSpace).First().BaseEntitySets;
for (int i = 0; i < fullNameTypes.Count; i++)
{
Type type = Type.GetType(fullNameTypes[i].FullName);
string schema = entitySets[type.Name].MetadataProperties["Schema"].Value.ToString();
}
}