...is not a foreign key column and cannot be used here? - linq-to-sql

I have two views in SQL, and have created mappings to them in Linq to SQL.
The two views have an association, which works fine, between Ticket.ProblemCode and Problem.Code
When I try to set UIHint("ForeignKey") on Ticket.ProblemCode and run the web page I get the error:
'ProblemCode' is not a foreign key column and cannot be used here.
Anyone know why? More importantly, how to fix it?

See this post on the ASP.NET forums:
http://forums.asp.net/t/1254559.aspx
Also, you said that you created the association in Linq to SQL. Is there an actual PK/FK constraint in the database, or is it only represented in your dbml?

Related

Issue with Database views in Entity Framework

I am working on a web application using entity framework and MySql. I have created some views and tables in my database but unfortunately ADO.Net data modal is not including the views. I have recreated my data modal but still views are missing. I have applied several solutions which i have found on different forums some one was suggesting to restart visual studio, Even some people was asking to restart the PC. but its not working for me.
Finally i have managed to solve this problem by adding a primary key column in my select statement.It was obvious that we must need a primary key to add our table in modal but as views have no primary key that's why i was confused. In short we must have to include at least one primary key column of a table in select statement.

Issue with multiple cascade paths

I have designed an diagram in sql server 2008.
as you can see in the photo:
Now in Value table I set the cascading delete ON for Feature and ProductDetail but I see the error below:
'Feature' table saved successfully 'ProductDetail' table saved
successfully 'Value' table
- Unable to create relationship 'ValueFeature'. Introducing FOREIGN KEY constraint 'ValueFeature' on table 'Value' may cause cycles or
multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO
ACTION, or modify other FOREIGN KEY constraints. Could not create
constraint. See previous errors.
What is it wrong with my design?
I think I have faced the same problem some years ago, in SQL server 2005. I suppose that nothing is wrong with your design. If you delete a Feature you want all the Value records to be deleted. Nothing wrong with that. If you don't have other cascades, the automatic delete will not propagate further. However, it seems that SQL Server is not clever enough to understand that, and does not allow you to have such a relationship, just because you have foreign keys that form a circle. I think that if you remove a foreign key (just for testing) and break the circle (for example delete the FK between the ProductDetail and Product) there would be no error.
Check this stackoverflow question too..
Hope I helped!

Mapping Exsisting DataBase Tables to Entity Framework is causing many problems

I have already existing DataBase inside SQL server 2008 around (300 tables) so I faced the following problems when i try to create an entity framework .edmx file:
If I specify to map all the 300 tables at once, the visual Studio will hang.
So I decide to include only the tables which I currently need, then the mapping will work fine. But if after that I add a new table to them, a Foreign key error will occur. So I have to delete the existing models and add them again with the new table. So the FK error will be removed.
So can anyone advice on how to overcomes these problems?
The error I usually got when adding a new table to the .edmx file will look something similar to.
Problem in mapping fragments starting at lines 2186, 2265:Foreign key constraint 'SDOrgPostalAddr_FK2' from table SDOrgPostalAddr (POSTALADDR_ID) to table AaaPostalAddress (POSTALADDR_ID):: Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side.
while if I added the table from the beginning then no error will be displayed.
Regards

Can't create Foreign Key

I wrote a simple SQL statement to create addon for wordpress - just few tables with relations.
I decided to test it a bit in MySQL workbench and all goes fine, got tables and relations. Then I'm trying to forward engineer it - workbench slightly changes the text... and then reports an error:
Honestly, I'm quite puzzled here... schema looks very simple, I'm sure I didn't make any type so why the error?
Make sure the columns are the same in both tables including sign for the foreign key and the primary key.
Could it be the engine? InnoDB handles foreign keys, but I think the standard MyISAM doesn't, or at least, didn't always, depending on version.
If you are trying to add the foreign key restriction to an attribute in a table containing data you can have problems if the foreign key restriction is not fulfilled. I mean, if you have a value in the attribute that now is a foreign key, and this value is not contained in the attribute of the table that the foreign key references.

Do i need to make sql tables using constraint to work with hibernate

I am using hibernate annotations with spring MVC.
Now i always create table using GUI editor like SQLYOG or phpmyadmin.
So i just create table with columns and even if i have some tables primaray key in other table , i just make that column with name like
Person ---id--name--age
SUbject------person_id----description
So i made those tables using GUI with mentioning anything about foreign key etc.
There is option in GUI editor ti make it primary kay and Auto increment so it usually works till now.
But i want to know that in Hibernate do i need to make tables with proper sql command . i mean do i need to mention which table is primary key and which is foreign key
or hibernate annotations are enough for that
Hibernate will work just fine as long as your annotations are correct.
But from a database design point of view I strongly suggest that you create at least the primary key and foreign key constraints.
Your queries will run much faster if you create the primary keys. You can improve performance a little more by creating other kinds of indexes to.
PHPMyAdmin is perfectly able to create primary keys for you, as well as every other index types there is in mysql. There's no need to write your creation code by hand.