I am working with the new EF4 CTP4, although I do not think there is much to do with it Trying to install a system where I can automatically add auditable fields to my database. The one I am trying to do connects the following two expressions:
a => New {a.Created By, a.CreatedTime, a.UpdatedBy, a.UpdatedTime} and
a => New {a.Id, a.Name}} Therefore the result
a => New {a.Id, a.Name, a.Created By, a.CreatedTime, a.UpdatedBy, a.UpdatedTime} As a result, I need to have an expression; Function & lt; T, object >>. I am pinging around and trying to do many things with expression. Invoke and expression And (more) and I did not find anything that is working for me.
I am not sure whether this is possible but any help would be appreciated.
I do not think you can 'merge' just two expressions. But you can use the optional API to create mapping with EntityMap .
Public Static Class MapBuilder {public static expression & lt; Func & lt; T, Object & gt; & Gt; GetMap & lt; T & gt; (Expression & lt; Func & lt; T, Object & gt; & gt; func) where T: IAuditable {var body = NewExpression as func.Body; Var Ultimate = Expression. Parameter (typef (t), "o"); Var property envelopex = new list & lt; Expression & gt; (); Foreach (Member Member Member Member) {propertyAccessExprs.Add (Expression Property (Ultimate, Member Name)); } Var props = typeof (IAuditable) .GetProperties (); Foreach (Propertyinfo PRO PRO) {propertyAccessExprs.Add (Expression Property (Ultimate, Prump.)); } Var columnMpin = new list & lt; Expression & gt; (); (Object), call (type) (column) ("column", new type [] {typef (object)}, expression conversion (access, type object)); } Var RowExpr = expression.col (EntityMap) .GetMethod ("line"), expression.NewArrayInit (EntityMapColumn, columnmapin)); Var result = expression. Lambda & lt; Func & lt; T, Object & gt; & Gt; (Roop xp, ultimate); Return result; }} Usage
var = creator = new model (); Builder.Entity & LT; SimpleAuditableObject & gt; () .HasKey (o = & gt; o.Id) .MapSingleType (MapBuilder.GetMap & lt; SimpleAuditableObject & gt; (o => New {o.Id, o.Name})); Where
Public Interface IAuditable {int CreatedBy {get; Set; } Time Created Time {Received; Set; } Updated {received; Set; } To get the time-lapse update time; Set; }} Public class SimpleAuditableObject: IAuditable {Public Ent ID (get; set;} public string name {get; set;} public int created {received; set;} public date time created time {receive; set;} public AntBET {Receive; Set;} Public Date Time Update Time {get} set;}} hH
Comments
Post a Comment