Telerik

Forums

Skip Navigation LinksHome / Community / Forums / OpenAccess ORM > General Discussions > How to map a view?

Not answered How to map a view?

Feed from this thread
  • tmlipinski Intermediate avatar

    Posted on Apr 24, 2009 (permalink)

    Hi,

    I know there is no straight support for mapping database views (yet). I try to do it manually - but how to declare that there is no primary key in such a "table"?
    Let's assume that my view is named "MyView" and has 2 columns: integer "MyInt" and string "MyString" (and none of them is unique and no pair of them is unique). How would it look like in app.config and in MyView.cs?

    Regards
    Tomasz

    Reply

  • Telerik Admin admin's avatar

    Posted on May 16, 2009 (permalink)

    Hi tmlipinski,

    Let us assume that we have two similar databases - DataBase1 and DataBase2. The first one has a View named "Combinations" exposing two colums (MyInt, MyString) from other tables. In DataBase2 we have a table also named "Combinations" with the desired MyInt and MyString columns of the same type as those in the View. We will use that table to reverse map a class with MyInt and MyString fields. The important part here is that we should set one of these columns as primary key. Otherwise the generated class will not compile. In this case the primary key can be the MyInt column. When we have mapped the DataBase2 to classes, we can just change the database name in the App.config file to "DataBase1". After doing so we can use the Combination class to retrieve the data from the view in DataBase1. The fact that we have a field marked as primary key in that class does not prevent us from reading records that may have same values in that column. Hope that helps.

    All the best,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • tmlipinski Intermediate avatar

    Posted on May 17, 2009 (permalink)

    Hi,
    OK, it works but with one important notice: this dummy declared primary key must be a unique key in this view. Otherwise we get something like this:
    - there are 3 records in the view (MyInt, MyString): (1, "A"), (1, "B"), (1, "C")
    - we ask for all records with MyInt = 1
    - we get 3 records in the result; but all of them are the same record - due to the caching mechanism, of course
    It's enough to declare a primary key containing both MyInt and MyString (as dummy as the previous one) to get the proper result.

    So: it works but I hope it is a temporary, very temporary :-) solution.

    Regards
    Tomasz

    Reply

  • Telerik Admin admin's avatar

    Posted on May 19, 2009 (permalink)

    Hi tmlipinski,

    Support for views is one of our targets for the near future but we cannot give a time-frame for that yet . We are going to prepare an article on that topic that customers can use as a know-how in the meanwhile.

    Sincerely yours,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / OpenAccess ORM > General Discussions > How to map a view?
Related resources for "How to map a view?"

OpenAccess ORM Features  |  Documentation  |  Demos  |  Telerik TV  |  Step-by-step Tutorial   ]

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.