Want to do a SELECT on a table without primary key

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
HDumas
Posts: 18
Joined: Fri 23 Sep 2005 12:56
Location: Quebec, Canada

Want to do a SELECT on a table without primary key

Post by HDumas » Fri 18 Mar 2011 17:30

Hello,
Using DotConnect for Oracle with VS 2010 and EF4.
I need to use LINQ to make SELECT queries on a view. The view in Oracle does not have a primary key.
The edml absolutely needs a primary so I created a fake one in the store model and mapped a column on it. But when I do a "from q in this.getAll()" it is looking for the column in Oracle... but it is not there. Will I have to ask our DBA to create a useless primary column just because my application absolutely needs one??

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 21 Mar 2011 17:56

No, there is no need to create a new fake column.
There are several possibilities.
I recommend you to use Devart Entity model:
1. Drop the view onto the model designer, and Entity Key will be inferred over the NOT NULL columns.
2. Select both columns, and go to the Properties.
3. Set the Entity Key property to false for both columns (this makes the entity invalid), and drag these columns onto the model surface.
4. Select New Complex Type, and delete the view from the Model.Store node in Model Explorer. Here is the Complex Type.
5. Right-click the Model.Store node and choose the Add Command Text... option. Paste the following SQL:

Code: Select all

declare cur sys_refcursor;
begin
  open :cur for select * from ;
end;
Do not regenerate the Parameters collection, and don't obtain metadata.
6. Go to Properties of the generated procedure, and set the value of the Result Set Parameter Name property to cur.
7. Here is the code to call the procedure:

Code: Select all

using(ScottModel.ScottEntities db = new ScottModel.ScottEntities()) {
        var q = db.Procedure1();
      }

Post Reply