Yes, you can do this, but the GUI designer won't be able to infer it for you.
The first thing the need to do is configure the view correctly.The designer cannot infer the primary key, so you will need to supply
that information.
You can now right-click in the empty space in the designer and then choose to add an association. Define the association between your view and table, setting the cardinality correctly.
In EF 1, you will need to remove the FK fields from the client schema by selecting them in the designer and pressing delete. This is because, in EF 1, you cannot have the same field mapped to both an association and in a scalar property. In EF 4, you can
keep the FK fields if you use FK associations, or you can use independent associations which behave like EF 1.
If you mean can you create a foreign key to or from a view, then the answer is no, you cannot. However, the underlying tables in the view can have FK's, which should produce the same effect.
If you mean can you JOIN a table and a view in a query, then the answer is yes, you can.
There is no need to set up a cascade between a view and its own underlying table. When records are deleted from the table, they will automatically disappear from the view.
reza141414
Participant
1571 Points
497 Posts
is it possible to create relation between TABLE and View
May 01, 2012 07:36 AM|LINK
hi
i have tbl and i have view...i need to make relation between them.
my view support delete and update and insert.
is it possible to create relation between this 2 kind of object?
thank's
dont forget to mark as answerd...
poojajoon
Member
228 Points
52 Posts
Re: is it possible to create relation between TABLE and View
May 01, 2012 07:41 AM|LINK
hey,
Yes, you can do this, but the GUI designer won't be able to infer it for you.
The first thing the need to do is configure the view correctly.The designer cannot infer the primary key, so you will need to supply that information.
You can now right-click in the empty space in the designer and then choose to add an association. Define the association between your view and table, setting the cardinality correctly.
In EF 1, you will need to remove the FK fields from the client schema by selecting them in the designer and pressing delete. This is because, in EF 1, you cannot have the same field mapped to both an association and in a scalar property. In EF 4, you can keep the FK fields if you use FK associations, or you can use independent associations which behave like EF 1.
reza141414
Participant
1571 Points
497 Posts
Re: is it possible to create relation between TABLE and View
May 01, 2012 08:55 AM|LINK
hi
i dont underestand what you seid!!! just i find the link that you copy your replay from there!!!
http://stackoverflow.com/questions/2184617/how-to-create-a-relationship-between-table-and-view-in-the-entity-framework
i dont want to use the EF ...
dont forget to mark as answerd...
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: is it possible to create relation between TABLE and View
May 01, 2012 12:48 PM|LINK
Can you show the script of your view?
You can check this link first http://msdn.microsoft.com/en-us/library/ms187956(v=sql.110).aspx
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
TabAlleman
All-Star
15571 Points
2700 Posts
Re: is it possible to create relation between TABLE and View
May 01, 2012 01:27 PM|LINK
If you mean can you create a foreign key to or from a view, then the answer is no, you cannot. However, the underlying tables in the view can have FK's, which should produce the same effect.
If you mean can you JOIN a table and a view in a query, then the answer is yes, you can.
reza141414
Participant
1571 Points
497 Posts
Re: is it possible to create relation between TABLE and View
May 02, 2012 05:54 AM|LINK
hi
ok thank'
this is my table:
and this is my View:
in this case is ti possible for cascade delete and Update?
dont forget to mark as answerd...
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: is it possible to create relation between TABLE and View
May 02, 2012 01:56 PM|LINK
You need to understand the limitations of updatable view before you move forward.
http://msdn.microsoft.com/en-us/library/ms180800.aspx
You can try to use trigger to do something you want to do.
http://msdn.microsoft.com/en-us/library/ms189799.aspx
I don't know your requirements for the cascading part. I would consider to implement a solution at the table level.
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
TabAlleman
All-Star
15571 Points
2700 Posts
Re: is it possible to create relation between TABLE and View
May 02, 2012 02:17 PM|LINK
There is no need to set up a cascade between a view and its own underlying table. When records are deleted from the table, they will automatically disappear from the view.