This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello I'd like to have a custom entity base class, deriving from Entity<TId>. Just like: public class EntityBase<TId> : Entity<TId> The new EntityBase is supposed to hold meta info on the entity (created, modified, deleted etc.). When I set it up with EntityBase having no fields at all, it is working. But when I create the private fields created, modified, and deleted, I get an exception when I start the project. It is a TargetInvocationException with an inner Exception, saying something like 'Unable to materialize field [Created] on type [LightSpeedTest.Product]. Check your table has an Id column and that your mappings are correct.' Is there any way that my tables all have those columns and all of my entities have according properties without having to implement this over and over again for every entity type, I have? Thanks for your replies. André |
|
|
I'm not sure about that error message but I have managed to inherit from a base class which in turn inherits from Entity. I wonder if EntityBase is "reserved" for internal LightSpeed use. It might be worth trying an alternative name for your base class. The other trick I needed was to set my own base class to be abstract and then use concrete inheritance on each of the Entities that inherit from it - if you use the default single table inheritance you will end up with just one big database table which is probably not ideal unless you are working with a very small Entity model. Here's the code that the LightSpeed designer created for me in case it helps: [Serializable] Chris |
|
|
Hey Chris Thank you for your response. I declared my EntityBase class as abstract class now and changed to name to entitytest. That doesn't solve my problem though. I still get the same exception. You're right: single table inheritance is not an option. We're developing a ticketing system for theme parks and museums and the data model is going to be complex. Would be horrible, having all the data is a single table André |
|
|
Hello Andre, As Chris says, you certainly should be able to inherit from a common base class and to put your common fields there. But of course in this case each table in your database must include columns for those common fields (concrete table inheritance). It sounds like your database table may not include a Created column or its type may not match that of the _created field. Can you drill down through the stack of inner exceptions and let us know what is in there please? Can you post your base and derived entity declarations, the CREATE TABLE script for your table, and the generated SQL for the LightSpeed query? Thanks! |
|
|
I am also trying to do the same thing. I do not want to use Single Table inheritance because it is causing issues with discriminators. I also have no need to add a field to every table. I have a base interface that I want to implement in the base along with some recursive helper functions. Right now I have to copy the code to 20+ files. Is there a way around this? Joe Feser |
|
|
Create a custom base class which implements the interface and helper functions, and derive from that: public class MyEntity : Entity<int>, IMyEntity { If you're using the designer, you can either: 1. Create MyEntity in the designer, drag an Inheritance arrow from Shipment to MyEntity, and set the Inheritance Type to ConcreteTableInheritance 2. Create MyEntity in code, register it with the designer as an External Class Reference (go to the model explorer and right-click the model node), and then select it as Shipment's Base Class via the Properties window. This reduces clutter in the designer because you don't have all those inheritance arrows, but does cause warnings on database synchronisation (because the designer doesn't know if the external class is introducing any persistent fields). In either case you will need to do this for each derived class -- you can't automatically tell the designer to use MyEntity as the base class -- though if you have a lot of classes you can cheat by writing a script to modify the .lsmodel file (which is just XML) directly. |
|
|
The ConcreteTableInheritance worked. Sorry it was not obvious for me. Thanks for the help. Joe Feser |
|