This is a migrated thread and some comments may be shown as answers.

how to get value from other table in orm

3 Answers 46 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MR
Top achievements
Rank 1
MR asked on 16 Apr 2011, 02:45 PM
Hi,

I have two tables

1)Inventorymaster
inventoryid  PK
name
lastname ..etc

2)InventoryImages
inventoryimagesid
inventoryid  FK
FullImagePath
primaryimage
etc...

from this i want to get fullimagepath in inventoryimagetable and primaryimage must be true
and all the data from inventorymaster table

i tried , but i cant able to get all data of inventorymaster ,
plz help me


3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 20 Apr 2011, 04:58 PM
Hi MR,

Normally OpenAccess should generate two classes in this case - InventoryMaster and InventoryImage. As the InventoryImages.inventoryid column is a foreign key, this means that the two tables are in 1:n relation and the generated InventoryMaster class will have a collection of InventoryImage objects (IList<InventoryImage>). On the other hand, the InventoryImage class will have a reference to its parent object - InventoryMaster.
You can use both the collection and the reference to navigate from one object to another.

If you want to combine data from both tables (do a projection) in a single object, you can use a linq query which returns instances of an anonymous class:
var result = (from i in context.InventoryImages
                where i.primaryimage == true
                select new
                {
                    FullImagePath = i.fullimagepath,
                    InventoryMaster = i.InventoryMaster
                }).ToList();

I hope that helps. Please let me know if you need more details or this is not what you are looking for.

All the best,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
MR
Top achievements
Rank 1
answered on 25 Apr 2011, 10:41 AM
I have attached table relationship for inventory-master and inventory-images,
i want to access  data in both the table using linq query

i have coding as u mentioned and i have attached here , but i could not able to access data of both the table

plz help me
0
Alexander
Telerik team
answered on 28 Apr 2011, 05:12 PM
Hi MR,

I am sorry but I am not able to understand what exactly you are trying to achieve. Could you please try to clarify what you would like to do? It would be helpful if you could show that in pseudo code, so I can get your idea better. Also, are you getting any exceptions or the code just does not do what you are expecting?

Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Data Access Free Edition
Asked by
MR
Top achievements
Rank 1
Answers by
Alexander
Telerik team
MR
Top achievements
Rank 1
Share this question
or