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, I've 3 important (for me) question: 1) I've see your product and now that i've tried the functionality is not so clear for me why i should use LightSpeed instead of Entity Framework.. Can you explain me in more detail LightSpeed advantage on MS EF? 2) I used inheritance in model editor and i think may be useful specify on entity base "Discriminator" (this is this is already possible) and a "Discriminator Type" (this is not possible now) field so when i deriving the editor can automatically generate Discriminator Field in the base entity table with right type and hide it in the diagram in the same manner it hide "id" field (i say this because i think Discriminator field is a framework field not a real model field and i don't like to see it in my model). 3) And now the more important question.. I need to convert in a conceptual model (with LightSpeed or EF) our databases but here come problems.. We have a central DB with all common table and some other db that add more specific table. Our application use all this db but i don't know how can i create a common model with satellite model without use Linked Model (we have a lot of link between various db's table with central db). What i want to have is a dll with common model and some dll that use common dll that i can use in my project for data access. How can i resolve this with your product? I hope you can help me. Morgan. |
|
|
Hi Morgan, re 2: When using inheritance you need to specify the type of inheritance on the inheritance relationship and then specify the property on the base entity which is used as the Discriminator. This property will be an entity property on the base and as such can not be hidden. We use the discriminator to determine what derived type to materialize a specific entity instance as when it is being loaded. re 3: Do you need these models to refer to each other, for example for the satellite model to extend the entities in the primary model? If so you can implement this by declaring your common model entities as part of a common library (assembly) and then including that as a reference in your application and extending it with your subsequent entities as neeeded. If you do this and you wish to use the LINQ provider you will likely need to implement your own strongly typed UnitOfWork to expose both sets of entities as part of the single strongly typed UnitOfWork class. Hope that helps and let us know if you have any more questions!
|
|
|
Hi Jeremy, reply 3: thanks for response, can you detail me how to achieve this in more detail? How can i use design editor if i extend my common model in a derived project? How can i use more database (one for common model and one for every extended model)? LightSpeed can handle this situation (split data and save it on more db) or i should handle it manually? And how? Morgan. |
|
|
Hi Morgan, You will want to set up and manage your common model in its own project first, any changes you make to the common model will then be made within that particular project. When creating your project containing the derived assemblies, you will first need to set up external class references for the LightSpeed designer to point to the entities you have created in your common model. To do this, open the "LightSpeed Model" window (by default this should be docked on the right hand side of the Visual Studio environment) and then you can right click on your model and select "Add New External Class Reference". In the properties for this you will need to specify the class name of the entity from your common model which you wish to import (and use as a base class for your derived entity). Once you have added this you can select that entity as a base class by right clicking on an entity on the design surface and setting the "Base Class" property accordingly. You will need to repeat this process for each of the entities in your common model which you are going to use as base classes in your derived model. To use multiple database connections you will need to use multiple LightSpeedContext's. Each context contains the information about how to connect to the database and which database provider and options to use. So you would create a new context for each new set of these options. You would then create a UnitOfWork under that context and operate over it as normal. I am a little unclear what you are referring to by "split data and save it on more db", can you give an example of what you are trying to do in practice?
|
|
|
Thanks for help, if i've a table person in common model and a table personWorker in derived model that inherit from person with distinct table (one for person and one for personWorker) when i want to save change made to personWorker in derive model db, lightspeed saves automatically data in person table on common model db too? Or i should handle this savechanges on separate db manually? More in general if in a derived model db i've a table related to a common db table how i should work? And how lightspeed handles this situation? Your response to the last question is valid for data query with linq too? Morgan |
|
|
Hi Morgan, When working with a model in a UnitOfWork all of the entities that are part of that model will need to be present in the underlying database being connected to. So if I am understanding you correctly you want your base classes to be stored in one database and your derived classes in a seperate database? If so this will not work if you are expecting to have these set up via an inheritance relationship in LightSpeed, or to be directly connected within your model. As an example lets say you have an entity called BaseEntity stored in DB1 and DerivedEntity in DB2. You would need to set up two seperate models, one for the entities in DB1 and one for the entities in DB2. The could be no direct relationships between BaseEntity and DerivedEntity (either inheritance or direct association) because in doing so LightSpeed would expect to find those database tables in both databases (which will be invalid in practice). So instead you would need to use a weak reference such as having a property on your entity which refers to the associated entity in the other database (e.g. DerivedEntity could have a property called BaseId which refers to the Id of the BaseEntity it is related to, but there would be no integrity checking performed by LightSpeed to ensure that BaseId actually matches a valid entity). Also because you would need to use two seperate UnitOfWork instances spanning two contexts to work with the two entities I suspect this would become quite convoluted to work with in practice. So you mentioned "when i want to save change made to personWorker in derive model db, lightspeed saves automatically data in person table on common model db too?" - this would not be possible. You would need to handle this manually. re: "Your response to the last question is valid for data query with linq too?" - yes this is definitely valid for both the LightSpeed querying API and when using the LINQ provider :)
|
|
|
So the only thing I can do is to logically extend the model in derived projects but the data must be in only one db with all entity in it because lightspeed can't handle more db. Right? You plan to add this possibility in the future? For logical model's extension where can i find a little example? Or your precedent response is complete? Thanks for your help. Morgan. |
|
|
Hi Morgan, Yes, your model when used within a UnitOfWork needs to be queryable and persistable so that means all entities need to be available within that database. You cannot split a model across multiple databases in the way you are wanting. At this stage we have no plans to add this support but I will record this on our issue tracking system so that if this becomes requested again in the future we can start prioritizing this. The information in the earlier post should be all that is required to extend the model across multiple projects using the designer - we dont have a specific example I can point you to but let us know if you run into any issues or have any further questions :)
|
|
|
Hi Jeremy, I tried to extend model by following your answer but is not clear for me how to relate entity of derived model with entity of common model so let me to show you an example of what i need to do: Common Model: Person(FirstName, LastName, Contacts), Contact(ContactType, Description), ContactType(Description) Derived Model: Employee: Person(EmployeeNumber), Company(CompanyName, Contacts) How you can see the common model has entity used for inheritance(Person) in the derived model (Employee) and entity in common model (Contact) used in derived model from other entity (Company). This is my situation, I can have all tables in one database but i need to separate the model for extending it with new requested programs and i don't know how to handle this with LightSpeed, the big problem here is that If i don't find a solution i've only 2 alternative: 1) What we do now: Use ADO.NET with sp in derived DB that call sp with the same name in common db for getting, update and save data from common table plus other sp for getting update and save entity in derived db with all the C# code necessary for use it in data access layer (bleah!!) 2) I can work with Entity (i like entity model) but i should to create one model with all entity (157 table). Can you save me? With a little simple clear example or work description like "LighSpeed for idiots step by step"? |
|
|
Hi Morgan, If I am understanding you correctly then these are the steps you will need to take.
You will now be able to create a new UnitOfWork targetting your Derived model and load in your Employee and Company records. e.g. using (var unitOfWork = new LightSpeedContext
|
|
|
Hi Jeremy, I done what you have said and all work right for inheritance but for Company-Contacts don't work because while Employee are People so inheritance is ok, Company has Contacts so Company should have a one-to-many association with Contacts. How can i insert this one-to-many association from Company to Contacts in Derived.Ismodel within design editor? Morgan. P.S. I found this discussion http://www.mindscapehq.com/forums/thread/2050 of marko that have my same problem. Is this discussion about technical limit of LS4 still valid? |
|
|
Yes, you cant have a direct association between Company and Contacts because Contacts would need a reverse association to Company and since this is in your derived model it has no idea about it. Outside of this though, how is a Contact going to know it belongs to a given Company instance? If this was modelled through the designer then we would create a CompanyId field in your Contact definition. You mentioned above that a Company was inheriting from a Contact though, but now you want it as an association? It would useful if you could give some more details about your model as I am a little unclear about what your current structure looks like to be able to suggest what you might be able to do here.
|
|
|
Hi Jeremy, I'm very sorry because I didn't express myself well, i need to derivate Employee from Persone and associate Company with Contact but i see now that isn't possible.. You plan to insert some functionality for this type of needing? Morgan |
|
|
Hi Morgan, No problem - I am still a little unsure of the specifics of your model though to be able to give a specific response, as mentioned earlier you can inherit from a model entity which isnt directly in your model by using the external class references however adding associations from your derived entities back to entities which are in a seperate model is not possible since we require the reverse association to be present on the base class definition as well. Assuming this is what you are meaning by "that isn't possible.." then no we are not intending to change the way in which we manage associations in the future. If you want to have an association between your derived class and your base class you would need to handle this manually since this will never be possible given the requirement for the base class to take a reference on the derived type. Manually meaning you would need to set up the association using custom code which you could put in a partial class instance on your derived class and then use the UnitOfWork property on the Entity to load in the child entities or parent entity as required, but you would then also need to manage any additions and removals from any child collections yourself manually as well so this could lead to a bit of hassle for you to have to implement.
|
|