How to draw Pimary Key and Foreign Key RelationShip in MS VISIO - visio

I am Drawing some ER Diagram for my application and need to draw primary and foreign key relationship between given entity but not find out any solution which works for me, Please if any one knows help me.
Thanks.....

Create a foreign key relationship with the Relationship tool
I have Spent Some Time And Got Solution:
Follow Below Link

Related

Why can't I have a referential constraint with a one to zero-to-one association?

I'm using entity framework 4.3 model first and can't figure out why I'm not allowed to have a one to zero-to-one association along with a referential constraint.
I have two main problems. I can't force referential integrity (without manual intervention) and my lazy loading doesn't seem to work... all my 1 to many associations are fine.
I basically have two tables, Loans and Contracts. The Contracts table has a scalar field for LoanId.
Until a loan is submitted, it does not have contract data and I chose not to place everything in the same table due to the size of the contract data. Ie. I don't want contract data retrieved from the database unless it is actually required.
I've searched around and can't seem to find any model first information that clearly answers my questions. Any information that may help me understand and clarify my problem would be greatly appreciated.
Regards
Craig
I guess LoanId field is not a primary key in Contracts table. In such case you cannot have such one-to-one relation because EF doesn't support it. When you create LoanId field in Contracts table the only way to force one-to-one relation is to add unique constraint on that field. EF currently doesn't support unique keys (except primary keys) so the only way to create one-to-one relation is to create relation between primary keys (Loan.Id <-> Contract.Id). If you don't follow this you will get error in designer.

How to decide a Primary Key from an Entity Collection programmatically

I'm encountering some problems importing my DB on Entity Framework. Some relationship between tables returns me some other entities without any primary key.. For my application I need to have a PK for every table.
Is there any way to say something like:
MyEntityCollection.SetKey("ColumnName")
Or something like that?
Thank you very much!
Take a look here, i discuss this in this answer,
EF4 Unknown Column In Field List
http://xhalent.wordpress.com/2011/01/21/configuring-entity-framework-4-codefirst/ has some detail around the two ways in EF4 of specifying a FK

Entity framework code first - association on "polymorphic" columns

I have 3 tables:
1. Invoice
InvoiceID int PRIMARY KEY
2. Order
OrderID int PRIMARY KEY
3. Transaction
TransactionID int PRIMARY KEY
Source int
Category string
On table "Transaction", Source (unfortunately) is behaving as a "polymorphic"(??) foreign key (there must be an actual term for that - sorry for my ignorance) that depending on the Category column it'll contain the ID of Invoice or Order.
However there's no actual foreign key.
Using EF 4.1 code first, anyone has any idea how I would create the proper associations?
Help is appreciated!
Thanks
Solution
Uh... Embarrassment is kicking in... I can just map it same way regardless of any actual DB foreign key.
I was having problems while trying to do that but basically wasn't related to this. I had computation properties that I didn't ask the context to ignore which was generating wrong queries.
You probably should create two nullable FKs instead of weak reference like that.
Uh... Embarrassment is kicking in... I can just map it same way regardless of any actual DB foreign key.
I was having problems while trying to do that but basically wasn't related to this. I had computation properties that I didn't ask the context to ignore which was generating wrong queries.

Entity Framework 4 - how to Delete from many-to-many relationships

Please can you help me to enable the deleting of books from my database?
I am using EF 4 and have a many-to-many relationship between books and authors. When I try to delete a book, I get the following:
he DELETE statement conflicted with the REFERENCE constraint "FK_BookAuthor_Book". The conflict occurred in database "C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL10.SQLEXPRESS\MSSQL\DATA\NTCODING.MDF", table "dbo.BookAuthor", column 'BookAuthor_Author_Id'.
The statement has been terminated.
Being a SQL guru is not what I do, but I think it is telling me that there is a record in the join table that also needs to be deleted. I'm not sure which property I need to set or what bit of coding I need to add.
If you can help me with this I would be really appreciative.
Thanks in advance
Nick
When you create the foreign key relation between the table book and the table lying between book and author (the one that breaks the many-to-many relationship in two one-to-many relationship), try to specify the "cascade" action at "insert and update specification". The same for the link between authors and the middle table. Thus, when you try to delete an author (or a book), all the dependent records from the middle table will be deleted.
Looks like my sql knowledge wasn't too bad. I hoped that by removing the authors from the book's collection of authors the join table would remove the records....a la fantastico!
I had to do this in the controller action of my web application because I use a generic repository and do not cast it to a book in there. So if you do know a way I could enforce this rule in my repository instead, that would be useful still.
Thanks

ADO.NET Entity Framework I can't see Foreign Key Property in Model

I have 2 table. In first table I have a Foreign Key link to second table's primary key.
(second)Personel and (first)Istbl are my tables.
In personel table I have PersonelID , PersonelName, PersonelSurname.
In Istbl table I have IsID, PersonelID, xx, xx, xx, going like this.
I can't see PersonelID in EF Model Viewer. I also can't see it in code screen.
Is there any example for me?
EF v1 hides foreign keys because it views them as persistence artifacts not important to the domain model. See here for a discussion.
EF v2, shipping with .NET 4, will include much better support for foreign keys in the model.
You can get foreign key value with something like this
object foreignKey = istblObject.PersonelReference.EntityKey.EntityKeyValues[0].Value;
Are you refreshing your datamodel? Have you created the model from the database, if so, try recreating it, if you have updated your database model.