Hi all. Newbie with a question...
I'm using CSLA Light to display a ReadOnlyList in a Silverlight DataGrid control -- works fine. My intention is to allow the user to select a record from the list and open an Edit form for that record. My ReadOnlyList should therefore contain keys. Here's the rub -- my db utilizes (and must continue to utilize) composite keys.
So I created a class that creates the keys for me. But when I attempt to LoadProperty in my BO, I get an error:
LoadProperty<OrderKey>(KeyProperty, OrderKey.Create().SetKeys(this));Type 'Business.OrderKey' with data contract name 'OrderKey:http://schemas.datacontract.org/2004/07/Business' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
I can avoid the problem by changing the key to a string (of delimitted field values) as follows:
LoadProperty<string>(KeyProperty, OrderKey.Create().SetKeys(this).ToString());
But I'm not sure that's desirable. In the following link, Rocky suggests using strings for keys, but wouldn't that involve the subsequent parsing of those strings to extract the individual values -- values that could otherwise be referenced as properties of a key object?
http://forums.lhotka.net/forums/1/457/ShowThread.aspx
So I have a couple questions:
1. Does anyone have a suggested/preferred solution for making an unknown class known to the data contract serializer? I'm not sure whether CSLA has facilities to do this.
2. Does anyone have direct experience and/or suggestions using CSLA with a composite key db? What are the pros/cons of using a key class vs. a string?
Thanks in advance for any thoughts.
If you convert your OrderKey to BB or ROB, the problem will go
away. Then again, why cannot you just use composite keys in your class?
This is the easiest route to go.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: mjr0607
[mailto:cslanet@lhotka.net]
Sent: Monday, February 09, 2009 3:47 PM
To: Sergey Barskiy
Subject: [CSLA .NET] CSLA Light : Serializing a Class to handle
Composite Keys
Hi all. Newbie with a question...
I'm using CSLA Light to display a ReadOnlyList in a Silverlight DataGrid
control -- works fine. My intention is to allow the user to select a
record from the list and open an Edit form for that record. My ReadOnlyList
should therefore contain keys. Here's the rub -- my db utilizes (and must
continue to utilize) composite keys.
So I created a class that creates the keys for me. But when I attempt
to LoadProperty in my BO, I get an error:
LoadProperty<OrderKey>(KeyProperty, OrderKey.Create().SetKeys(this));
Type 'Business.OrderKey' with data contract name
'OrderKey:http://schemas.datacontract.org/2004/07/Business' is not expected.
Add any types not known statically to the list of known types - for example, by
using the KnownTypeAttribute attribute or by adding them to the list of known
types passed to DataContractSerializer.
I can avoid the problem by changing the key
to a string (of delimitted field values) as follows:
LoadProperty<string>(KeyProperty, OrderKey.Create().SetKeys(this).ToString());
But I'm not sure that's desirable. In the following link,
Rocky suggests using strings for keys, but wouldn't that involve the
subsequent parsing of those strings to extract the individual values
-- values that could otherwise be referenced as properties of a key object?
http://forums.lhotka.net/forums/1/457/ShowThread.aspx
So I have a couple questions:
1. Does anyone have a suggested/preferred solution for making an
unknown class known to the data contract serializer? I'm not sure
whether CSLA has facilities to do this.
2. Does anyone have direct experience and/or suggestions using CSLA with a
composite key db? What are the pros/cons of using a key class vs. a
string?
Thanks in advance for any thoughts.
Sergey,
Thanks for the response. Following a brief distraction, I'm finally back on this project. I tried your first suggestion of deriving the OrderKey class from BusinessBase. That worked fine, but as expected, there's a lot of overhead. Populating a grid with 10,000 orders takes 10 seconds without keys and 24 seconds with keys.
I then tried creating a nested OrderKey class within my OrderInfo business class as follows:
[
Serializable] public partial class OrderKey{
public string OrderClass { get; set; } public string OrderNumber { get; set; } public static OrderKey Create(){
return new OrderKey();}
public OrderKey SetKeys(OrderInfo theOrderInfo){
this.SetOrderClass(theOrderInfo.OrderClass)
.SetOrderNumber(theOrderInfo.OrderNumber)
;
return this;}
public OrderKey SetOrderClass(string theOrderClass){
this.OrderClass = theOrderClass; return this;}
public OrderKey SetOrderNumber(string theOrderNumber){
this.OrderNumber = theOrderNumber; return this;}
}
But that resulted in the same error described in my original post -- even if I derive OrderKey from CriteriaBase. It seems that only business classes (not Criterias) are properly ferried in CSLALight -- true??
You suggested that using composite keys in my class would be the easiest way to go. I'm not sure what you mean (newbie). Would you mind providing a brief explanation/example?
Thanks in advance for your time.
Copyright (c) Marimer LLC