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
|
Hi there, I've created a domain model for my SL app that is to be consumed by WCF Ria - as usual I've decided that while I'm on to something, I might as well learn a thing or two. In my model I'm attempting to create entities that going to be represented via a treeview (an article tree). The general concept is to utilize inheritance - since lightspeed supports it (and since the SL treeview doesn't really work well with multiple item types - unless they share a base class - then it's 'doable'). The entities deriving from the TreeItem are Article and ArticleGroup. Also, since the whole thing is to be exposed via RIA , I've added DataContract attributes to all classes in this hierarchy + a partial imlementation of the TreeItem entity which I've decorated with KnownType for both deriving entities - so that WCF Ria would play nice.
I've added a nullable One-Many relation between ArticleGroup and the base class, representing the fact that an article group may contain sub groups or child-articles. I've added a nullable One-Many relation between ArticleGroup and Articles so that I could quickly get all articles related to a group.
(drumroll)
I've fired up my solution, and performed a login action (which is completely) unrelated to the above, but it did fail b/c LightSpeed was telling me that hierarchical relations can't be eager loaded. I've quiclly consulted the properties of the forementioned relations and verified that EagerLoading was set to false in both cases, however - at that time I did specifiy 2 named aggregates that I intended to use later (for loading child tree nodes & articles). Having cleared those aggregate names - the exception didn't surface again. I'm confused, how does this work ? Can I still achieve what I've originally intended ? Below is my .lsmodel file.
<?xml version="1.0" encoding="utf-8"?> <model xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.1.0.0" name="Domain" targetNamespace="Ciopan.Domain" databaseProvider="MySql5" connectionString="server=localhost;User Id=root;password=p@ss;Persist Security Info=True;database=ciopan" pluralizedInDatabase="true" mediumTrustCompatibility="false" migrationProjectName="Ciopan.Domain.Migrations\Ciopan.Domain.Migrations.csproj" xmlns="http://namespaces.mindscape.co.nz/lightspeed"> <entities> <entity name="Role" identityType="Int32" cacheExpiry="0" tableName="roles"> <entityProperties> <entityProperty name="Name"> <validations> <presenceValidation /> <lengthValidation minimumLength="0" maximumLength="45" /> </validations> </entityProperty> </entityProperties> <oneToManyAssociations> <oneToManyAssociation Id="6287ff8e-e98e-49b7-aec5-ebd3fce1bc06" collectionName="Userroles" backreferenceName="Role" isNullable="false"> <entityMoniker name="/Domain/UserRole" /> </oneToManyAssociation> </oneToManyAssociations> </entity> <entity name="UserRole" identityType="Int32" cacheExpiry="0" tableName="userroles" /> <entity name="User" identityType="Int32" cacheExpiry="0" tableName="users"> <entityProperties> <entityProperty name="Name"> <validations> <presenceValidation /> <lengthValidation minimumLength="0" maximumLength="45" /> </validations> <clrAttributes> <clrAttribute typeName="System.ComponentModel.DataAnnotations.KeyAttribute" /> </clrAttributes> </entityProperty> <entityProperty name="Password"> <validations> <presenceValidation /> <lengthValidation minimumLength="0" maximumLength="100" /> </validations> </entityProperty> </entityProperties> <oneToManyAssociations> <oneToManyAssociation Id="ed89f9ef-87da-47bc-bd2e-03e4ddba00f4" collectionName="Userroles" backreferenceName="User" isNullable="false"> <entityMoniker name="/Domain/UserRole" /> </oneToManyAssociation> <oneToManyAssociation Id="8b85dc3a-4bf1-44ad-930d-f65a275c0e1c" collectionName="Articles" backreferenceName="User" isNullable="false"> <entityMoniker name="/Domain/Article" /> </oneToManyAssociation> </oneToManyAssociations> </entity> <entity name="ArticleGroup" identityType="Int32" cacheExpiry="0" tableName="articlegroup"> <entityProperties> <entityProperty name="Name"> <validations> <presenceValidation /> <lengthValidation minimumLength="0" maximumLength="100" /> </validations> </entityProperty> </entityProperties> <oneToManyAssociations> <oneToManyAssociation Id="912f9dbc-f09c-406f-be45-3f6387f0d417" collectionName="SubGroups" backreferenceName="ParentGroup" isNullable="true"> <entityMoniker name="/Domain/TreeItem" /> </oneToManyAssociation> <oneToManyAssociation Id="0092da19-ed6d-44a0-aba5-5de8c5640c02" collectionName="Articles" backreferenceName="ArticleGroup" isNullable="true"> <entityMoniker name="/Domain/Article" /> </oneToManyAssociation> </oneToManyAssociations> <clrAttributes> <clrAttribute typeName="System.Runtime.Serialization.DataContractAttribute" /> </clrAttributes> </entity> <entity name="Article" identityType="Int32" cacheExpiry="0"> <entityProperties> <entityProperty name="Title"> <validations> <presenceValidation /> <lengthValidation minimumLength="0" maximumLength="100" /> </validations> </entityProperty> <entityProperty name="Content" dataType="Blob" isNullable="true"> <validations> <lengthValidation minimumLength="0" maximumLength="65535" /> </validations> </entityProperty> </entityProperties> <clrAttributes> <clrAttribute typeName="System.Runtime.Serialization.DataContractAttribute" /> </clrAttributes> </entity> <entity name="TreeItem" identityType="Int32" cacheExpiry="0"> <derivedClasses> <baseToDerivedAssociation discriminatorName="TreeItemType" discriminatorValue="1"> <entityMoniker name="/Domain/ArticleGroup" /> </baseToDerivedAssociation> <baseToDerivedAssociation discriminatorName="TreeItemType" discriminatorValue="2"> <entityMoniker name="/Domain/Article" /> </baseToDerivedAssociation> </derivedClasses> <clrAttributes> <clrAttribute typeName="System.Runtime.Serialization.DataContractAttribute" /> </clrAttributes> </entity> </entities> <reminders> <reminder Id="f5a1ab4f-5696-404b-8ffe-19af5ac7f147" text="User.Name requires System.ComponentModel.DataAnnotations.KeyAttribute for WCF Ria Authentication" author="Maciek" /> <reminder Id="3754df51-8043-4a56-a659-1ec948204089" text="TreeItem requires a DataContract + KnownType(Article) + KnownType(ArticleGroup)" author="Maciek" /> <reminder Id="ca7fe907-a2e0-4cf4-8460-bf45c793d9aa" text="ArticleGroup->Article MUST NOT be eager loaded, same goes for ArticleGroup->SubGroups" author="Maciek" /> </reminders> </model> |
|
|
The reason you see the exception even on unrelated actions is that when LightSpeed loads your domain model it checks that it will be able to handle it. This includes checks for things like circular associations or hierarchical eager loads anywhere in the model. LightSpeed has noticed the hierarchical eager load elsewhere in your model and raises the exception because it knows that isn't supported -- you'll never be able to use that association I realise you put a named aggregate on it rather than an always-eager, but LightSpeed still raises the exception because you can never specify that named aggregate (because if you did, it would result in LightSpeed trying to eager load a hierarchical relation). As you've found, removing the aggregates fixes the problem, because now the relation can only ever be lazy, which is safe -- and you're not losing anything because you could never have used that named aggregate. Does this answer your question? If you have concerns that are more around the data contract stuff then I'll get Jeremy to pitch in, but hopefully this clarifies what is going on at the LightSpeed level. |
|
|
Hello again,
I've finally had some time to work on this a bit more, I've created a class hierarchy and attempted a submit operation via WCF Ria. For the record, I'm using class table inheritance. My goal is to create a collection of TreeItems for a silverlight treeview. therefore there's the base entity TreeItem + 2 deriving entities. When I've attempted to submit an object via WCF Ria, I got the message saying that I can't use IdentityColumn while using ClassTableInheritance. Could you elaborate on that please?
Regards |
|
|
You can't use IdentityColumn with class table inheritance, because a CTI entity is spread across multiple tables. Each table would have its own identity sequence so the rows in different tables could end up with different IDs. Therefore, LightSpeed requires that you use a different identity method, so that it can insert the same ID in each table of the CTI hierarchy. |
|