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
|
Howdy All, I have this situation where currently Entity "A" is in a one to many association with Entity "B". The model correctly creates the property of Entity "A" that is all of the Entity "B"s associated with it through the association. Now I have a new need where I would like to build a collection in Entity "A" of certain Entity"B"'s that meet a certain criteria... What would be the best route to create that new association/query??? How does one "override" the default select all type of operation that currently happens with the original association??? Obviously, I don't want this over-ridden on any rebuilds of the model, so It will go in a created partial clsass for Entity "A"... Just not sure as to how to go about specifying the selection string. Do I add a new "Association" to the Entity, and if so how do I override the selection, or do I make a function that just returns a list??? Sorry for being slightly redundant in my explaination above :-)! Thanks in advance, Kevin Orcutt GIS Developer/Consultant City of Cincinnati - Cincinnati Area GIS (CAGIS) (513) 850-1335 (cell) Kevin.Orcutt@cincinnati-oh.gov www.cagis.org |
|
|
If I'm reading this right: create a method in a partial class that returns a list. If you create an association you'll probably get an exception stating that LightSpeed doesn't support circular references when you initialize. |
|
|
That's more or less of the solution I came up with... I added a property in my partial class that returns a entitycollection... However, Here's my next BIG question... I have separated out my Model into it's own project and made it a dll. My context is in the main project. Would I pass that into the property in my partial class, or just instantiate a new temporary one in my property to get the collection??? Inquiring minds want to know! :-) Thanks again in advance, Kevin Orcutt |
|
|
The way I do it: the partial class would be of type EntityA and would exist as part of the Model dll. An alternative is to build helpers off your strongly-typed UnitOfWork. There are already wrappers that return IQueryable; you add more that return IQueryable, IEnumerable or IList depending on what you need. E.g., for a Machine table there's already a uow.Machines.Where(x=> ...). You can add at that layer (essentially the Repository pattern), or hang additional stuff off the entity depending on how much logic you need. |
|
|
I was planning on adding it to the partial class of type Entity"A" in the model, as you suggested :-)... In doing so, I was also planning on using LINQ ??? to aid in the selection (in other words, make the selection as easy as possible :-) ) But as such, don't i need a Context AND UnitOfWork to do the selection, or is there a better way to access what I need from within the Entity??? |
|
|
No one answer: it depends on how you're managing the unit of work (web app? client app? short running/multiple users? long running, no contention?) and how you want to structure the access. Depending on the type of association and needed logic sometimes it's convenient to go bottom up through the entity, other times you might prefer to go top down through the uow. Share a little more about your app and people can probably link you to some of the common practices. |
|
|
Within an Entity you have access to the UnitOfWork attached to the entity itself through the UnitOfWork property, so if you are setting up a property which needs to do any subsequent work you can just call UnitOfWork.Find<> or UnitOfWork.FindById<> etc. e.g.
If you want to use LINQ note that you wont have access to your typed UnitOfWork but you can just include the Mindscape.LightSpeed.Linq namespace and then use the UnitOfWork.Query<>() extension method to get yourself an IQueryable to work against.
|
|
|
That might be just the thing I'm looking for... I'll be the first to admit that I'm more of a VB.net type of guy as opposed to C#, so would it trouble you too much to provide a VB example of using the Find() method. I'm having a little trouble getting my to work. Also, I'll add a caveat, that the expression that I need has a couple of attributes that I want to test for/search for... Here's my code and it's definately having MAJOR issues with what I'm trying :-(((
Thanks in advance!, Kevin Orcutt |
|
|
I believe you will want to make the following modification to your code above, apologies for any VB syntax issues:
If not can you give some more details on the issues you are having?
|
|
|
OK, I thought it would work, but I get an error now on the return statement: Unable to cast object of type 'System.Collections.Generic.List So my thought is to create a entitycollection within the property and iterate over the iList and add to the EntityCollection... Or might there be a better way of achieving same goal??? :-)
Thanks in advance, kevin Orcutt |
|
|
Sorry my mistake in not pointing this out in the earlier post. UnitOfWork.Find<> returns an IList
|
|