Just like I told in another post (http://groups.google.com/group/
fluent-nhibernate/t/9eb53f6447e9771a) I use to set some dynamic
filters on my entities. Actually I have to do a very ugly workaround
so I can acomplish that, for the definitions I have to emit code to
make the FilterDefinitions inherited classes and for the mapping
classes I have to set a static property with the filters witch it has
to Apply (when just it needs is the filter name). I think it should be
very better if you could add two more overloads in the
ClassMap<T>.ApplyFilter method, those should be:
public ClassMap<T> ApplyFilter(string name)
{
return this.ApplyFilter(name, null);
}
public ClassMap<T> ApplyFilter(string name, string condition)
{
var part = new FilterPart(new TFilter().Name, condition);
filters.Add(part);
return this;
}
And the current one could be changed to:
public ClassMap<T> ApplyFilter<TFilter>(string condition)
where TFilter : FilterDefinition, new()
{
return this.ApplyFilter(new TFilter().Name, condition);
}
That should solve part of my problem, second I would have the
FluentMappingsContainer.Add restricting me to add just types and
forcing me to emit code for the filter definitions as, also, set
static properties of my entities mapping classes so they know witch
filters should they apply when I could just instantiated then, set the
filters on then an pass this instance to the
FluentMappingsContainer.Add.
Would be something like:
public class FluentMappingsContainer
{
private readonly IList<IMappingProvider> mappings = new
List<IMappingProvider>();
private readonly IList<IFilterDefinition> filters = new
List<IFilterDefinition>();
...
public FluentMappingsContainer Add(IMappingProvider mapping)
{
mappings.Add(mapping);
WasUsed = true;
return this;
}
public FluentMappingsContainer Add(IFilterDefinition filter)
{
filters.Add(filters);
WasUsed = true;
return this;
}
internal void Apply(Configuration cfg)
{
foreach (var mapping in mappings)
{
model.Add(mapping);
}
foreach (var filter in filters)
{
model.Add(filter);
}
foreach (var assembly in assemblies)
{
model.AddMappingsFromAssembly(assembly);
}
foreach (var type in types)
{
model.Add(type);
}
if (!string.IsNullOrEmpty(exportPath))
model.WriteMappingsTo(exportPath);
model.Configure(cfg);
}
I have posted this last year (http://groups.google.com/group/fluent-
nhibernate/browse_thread/thread/fdc23fd8197d9bbc/
743077793216c027#743077793216c027) but got nothing, to my happiness I
haven't to change fluentnh code that time as in that case was for
dicriminating classes witch have it's behavior changed to use
SubclassMap<T>. I'm not posting a real case because the code is long
and uggly and I don't see that those overloads should be a major
change in the FluentNHibernate structure (enlighten me if I'm wrong),
all those code have been tested here and worked fine I just don't use
them because if I make a change on FluentNHibernate I'll have to peek
it on every new version I download, too messy, error prone,
whatever...
Best Regards,
DM
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
You mention above that you Apply it just by the name. Why? The
FilterDefinition classes are hardly more than a few properties and
methods for generating some mapping information. It's not going to
hurt you particularly badly if you just use the methods already
existing. The code you provided wouldn't compile anyway, I believe in
your second method you meant "new FilterPart(name, condition);"
TFilter is not defined.
Your proposed changes to FluentMappingsContainer are TOTALLY
superfluous. You've added additional overloads for the Add method
taking instances rather than types. Instead of
FluentMappingsContainer.Add(), you can call the PersistenceModel
directly for this purpose:
FluentMappingsContainerInstance.PersistenceModel.Add(IFilterDefinition
or IMappingProvider). If you need to set the WasUsed property on the
mappings container, either pass in an dummy empty mapping class or use
reflection to modify it. Here's an extension method I use:
public static void BecomeUsed(this FluentMappingsContainer m)
{
PropertyInfo pi = m.GetType().GetProperty("WasUsed",
BindingFlags.NonPublic | BindingFlags.Instance);
if (pi != null)
pi.SetValue(m, true, null);
}
On Mar 15, 10:00 am, Daniel Mirapalheta <mirapalh...@gmail.com> wrote:
> I just checked both classes (in the following links) and nothing of that
> have been added.
>
> http://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentN...http://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentN...
>
> Regards,
> DM
>
> 2010/3/15 snicker <ngordon...@gmail.com>
> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.