how to get value from other table in orm

4 posts, 0 answers
  1. MR
    MR avatar
    4 posts
    Member since:
    Mar 2009

    Posted 16 Apr 2011 Link to this post

    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


  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 20 Apr 2011 Link to this post

    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
  3. DevCraft banner
  4. MR
    MR avatar
    4 posts
    Member since:
    Mar 2009

    Posted 25 Apr 2011 Link to this post

    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
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 28 Apr 2011 Link to this post

    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
Back to Top