I have the following class that I am using and I was wondering if I have
a good mapping for it or if I can do better...
[Serializable]
[ActiveRecord(Table = "UserProvidedPropertyContainers")]
public class UserProvidedPropertyContainer :
ActiveRecordBase<UserProvidedPropertyContainer> {
IDictionary<string, string> _properties;
public UserProvidedPropertyContainer() { _properties = new
Dictionary<string, string>(); }
[PrimaryKey(PrimaryKeyType.GuidComb)]
public virtual Guid Id { get; set; }
[Property("ContainerName", NotNull = true)]
public virtual string ContainerName { get; set; }
[Property("CreatedDate", NotNull = true)]
public virtual DateTime CreatedDate { get; set; }
[Property("Data", ColumnType = "Serializable", NotNull = true)]
public virtual IDictionary<string, string> Properties { get {
return _properties; } set { _properties = value; } }
}
This mapping works for what I need right now (provided I use IMAGE for
the Data column type instead of VARBINARY(8000)), but I feel wary merely
slapping on "Serializable."
The UI story is essentially that the client can define custom properties
on pretty much anything and then can use those custom properties as
strings in reports (technically they become xml elements output via
rendering a spark template, but that really isn't important).
I considered storing the properties in a separate table, but I couldn't
figure out how to map to this IDictionary<string,string> property; at
least not without having a significant amount of extra code (mapping a
different class, making this class a facade and then either changing
every usage of this class to know about the facade or creating an
IRepository interface that doesn't expect the class to implement
ActiveRecordBase).
Console testing program:
class Program {
static void Main(string[] args) {
try {
InPlaceConfigurationSource source =
InPlaceConfigurationSource.BuildForMSSqlServer("localhost\\SQLEXPRESS",
"test");
ActiveRecordStarter.Initialize(source,
typeof(UserProvidedPropertyContainer));
ActiveRecordStarter.GenerateCreationScripts("output.sql");
using (var reader = new StreamReader("output.sql")) {
Console.WriteLine(reader.ReadToEnd());
}
/*
returns:
create table UserProvidedPropertyContainers (
Id UNIQUEIDENTIFIER not null,
ContainerName NVARCHAR(255) not null,
CreatedDate DATETIME not null,
Data VARBINARY(8000) not null,
primary key (Id)
)
Actual table:
create table UserProvidedPropertyContainers (
Id UNIQUEIDENTIFIER not null,
ContainerName NVARCHAR(255) not null,
CreatedDate DATETIME not null,
Data IMAGE not null,
primary key (Id)
)
* */
var obj = new UserProvidedPropertyContainer {
CreatedDate = DateTime.Now, ContainerName = "test" };
obj.Properties["test"] = "thetest";
using (var scope = new TransactionScope()) {
obj.Create();
scope.VoteCommit();
}
Console.WriteLine(UserProvidedPropertyContainer.Find(obj.Id).ContainerName);
} catch (Exception exception) {
Console.WriteLine(exception.ToString());
}
Console.ReadKey();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---