classMap.HasSet(x => x.SetOfChildren);
?
classMap.HasMany(x => x.SetOfChildren);classMap.HasMany(x => x.SetOfChildren).Type(ManyType.Bag).ForeignKey("PersonId");
So just to make sure I'm not misunderstanding.. You don't want this:classMap.HasSet(x => x.SetOfChildren);
?
I expected there might be arguments about the idea of HasSet, which is
part of why I floated the idea rather than just commiting, but this
isn't one I was expecting.
Isn't it obvious that the relationship type is Set? I must be missing something.
Ahh, now I follow. Part of the reason I was fond of HasSet is that I
could customise the signature so that the child type would be
inferred. But I see your point.
Chad, have you already got an implementation using that api? If not I
am happy to implement it. But what's the m => m for?
I'm also not following the difference between HasElementsOf and HasMany.
var classMap = new ClassMap<Parent>()
.HasMany<Child>(x => x.Children, m => m
.AsBag()
.Etc())
.Map(x => x.Name)
.Map(x => x.StartDate)
.Map(x => x.Etc);
This requires quite a few changes as other methods such as Map would
also have to chain off a lambda parameter and return the classmap.
Certainly possible, but too much for me to tackle in one go.
I will see how far I can get tonight.
[TestFixture]
public class NHibernateTester
{
[Test, Explicit]
public void CanCompileSimplestMapping()
{
var map = new ClassMap<MappedEntity>();
map.Map(e => e.Name, "Name");
map.Id(e => e.Id, "Id");
XmlDocument xml = map.CreateMapping(new MappingVisitor());
IDictionary<string, string> props = getProps();
var config = new Configuration();
config.AddProperties(props);
config.AddXml(xml.InnerXml);
config.BuildSessionFactory();
var exporter = new SchemaExport(config);
exporter.Create(true, false);
// do whatever tests here I guess
config.ClassMappings.Count.ShouldEqual(1);
}
private static IDictionary<string, string> getProps()
{
IDictionary<string, string> props = new Dictionary<string,
string>();
props.Add("connection.provider",
"NHibernate.Connection.DriverConnectionProvider");
props.Add("connection.driver_class",
"NHibernate.Driver.SqlClientDriver");
props.Add("dialect", "NHibernate.Dialect.MsSql2000Dialect");
props.Add("hibernate.dialect",
"NHibernate.Dialect.MsSql2000Dialect");
props.Add("use_outer_join", "true");
props.Add("connection.connection_string",
"Data Source=.;Initial
Catalog=ShadeTree;Integrated Security=True;Pooling=False");
//props.Add("show_sql", showSql);
props.Add("show_sql", true.ToString());
return props;
}
}
public class MappedEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
and get a nice, friendly (and slow) output of:
------ Test started: Assembly: FluentNHibernate.Testing.dll ------
if exists (select * from dbo.sysobjects where id =
object_id(N'MappedEntity') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table MappedEntity
create table MappedEntity (
Id INT IDENTITY NOT NULL,
Name NVARCHAR(100) null,
primary key (Id)
)
1 passed, 0 failed, 0 skipped, took 3.22 seconds.
>>>> On Thu, Jul 31, 2008 at 1:18 PM, James Gregory <jagreg...@gmail.com>
>>>> On Thu, Jul 31, 2008 at 1:18 PM, James Gregory <jagregory.com@gmail.com>
>>>> On Thu, Jul 31, 2008 at 1:18 PM, James Gregory <jagregory.com@gmail.com>
I agree about dropping the inner-lambda. I forgot that the mapping FI already had dead-ends, so it’s cool.
Sorry about the confusion.
-c
That's it. Terminating methods and a builder hierarchy are sort of
ugly. Not to mention cumbersome to design (although it may eventually
come down to that). Not that all that lambda "syntactical tar" is
super clean, but I think I like it better also.