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 - LightSpeed 5, fairly recent nightly build, .NET 4.5, C#, VS 2013. A (long!) while back I asked how to do this, and now I'm looking for a better way. Say I have 2 tables, TestRecords and Items. Obviously there are a lot more than 2 but this works for now. The Items table is rerferenced by a foreign key field in TestRecords, so TestRecord.ItemID matches Item.ItemID. My constraint is that I don't want to create multiple identical Item records so I want to find any existing Item record that matches the one I am trying to save. To do this I created a method called FindExisting(Item item) that returns a matching Item record or null. It is used by passing an Item record to FindExisting like this:
I am relatively sure this snippet came from one of you guys down there, but can't find the original thread. Anyway, I want to make this generic and was wondering how you all implemented OfType Also, if I reverse the order with the existing code (OfType This doesn't sound very complete somehow but I'm running out of time. Please give me whatever bone you can given this limited description and tell me what else you need and I will try to flesh it out next week. Thanks! Dave Newman |
|
|
.OfType
If you were wanting to implement something yourself you just need to pass in a type variable and you could achieve this by:
You dont need to use this with a database query as there is always a known entity type specified as part of the query. If you reverse the order of the existing code you will avoid a database call.
|
|
|
Thanks Jeremy! That answers my questions for now. I may have a few more as I attempt to "genericize" some the code in my service app, but this helps me get started. Dave |
|