Rob: Just FYI, as far as I understand temp will still exist at the time because it's used within the closure. .Net imports that variable into the lambda's scope.
On Sat, Jun 20, 2009 at 4:32 PM, Pablo Ruiz <[email protected]> wrote: > > private void SetupComponentParts(DynamicComponentPart<IDictionary> part) > { > IList<string> dynamicColumns = GetCustomerColumns(); > foreach(string col in dynamicColumns) > { > string temp = col; // Avoid any modified closure issues. > c.Map(x => (string)x[temp]); > } > } > > DynamicComponent(x => x.AdditionalFields, c => SetupComponentParts(c)); > > > That's it.. > > > On Sat, Jun 20, 2009 at 5:11 PM, rob <[email protected]> wrote: > >> >> Funny...this is exactly my situation. See my post on Dynamic >> components from a couple days ago. Unfortunately, this statement won't >> work: >> c.Map(x => (string)x[temp]); >> >> because the variable temp isn't evaluated in the loop; the statement >> is turned into an expression tree and evaluated later; at which time >> "temp" won't exist. I've been trying all sorts of things the past few >> days, and may be close to a solution involvoing manually building the >> expression tree. Should know more on Monday. Keep me posted if you >> figure something out! >> >> On Jun 20, 8:45 am, Paul Batum <[email protected]> wrote: >> > Hi Silvia, >> > >> > Can the column details be discovered at startup time? I'm thinking of >> > something like this: >> > >> > IList<string> dynamicColumns = GetCustomerColumns(); >> > DynamicComponent(x => x.AdditionalFields, c =>{ >> > foreach(string col in dynamicColumns) >> > { >> > string temp = col; // Avoid any modified closure issues. >> > c.Map(x => (string)x[temp]); >> > } >> > >> > }); >> > >> > Paul Batum >> > >> > On Tue, Jun 16, 2009 at 10:10 AM, Silvia <[email protected]> wrote: >> > >> > > I have the below situation that I need help figure it out. >> > > I am using fluent nhibernate with a legacy database. I need to map >> > > some additional columns to a dictionary(?) property in my entity >> > > dynamically, because I do not know the number of columns and column >> > > names and other specifications at compile time and I dynamically need >> > > to work with those columns(insert,update...).There is another object >> > > which has those information and has a relationship with my main entity >> > > based on the value of two other columns.Is this possible in >> > > nhibernate? >> > > I tried to use DynamicComponent but the problem is I don't know what >> > > would be the properties in my component. >> > > I have something like this: >> > >> > > In Entity.cs : >> > > public virtual IDictionary AdditionalFields { get; set; } >> > > public virtual Info AdditionalFieldsInfo{get; set;} >> > >> > > And in EntityMap.cs: >> > > References(x => x.AdditionalFieldsInfo); >> > > and I supposedly should have something like this: >> > > DynamicComponent(x => x.AdditionalFields , m => >> > > { >> > > m.Map(?Which I don't know how to map because I dont have the number of >> > > columns to be mapped and column names.These information needs to come >> > > from AdditionalFieldsInfo); >> > > }); >> > >> > > I also posted the question to nhusers group([email protected]) >> > > but I still not very sure how to implement this. >> > > I do appreciate if someone could help. >> > > Thanks. >> > > Silvia >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
