Address.cs
AddressType.cs
Customer.cs
Order.cs
New project, SalesModel.DataLayer
SalesModelContext.cs : DbContext
Install Entity Framework Power Tools, click TOOLS –> Extensions and Updates…
Search and Download it
Run “View Entity Data Model(Read-only)” by right click on the .cs file
Error 1, incorrect connection string, but the error is misleading, since we don’t need any connection string is this moment.
Solution: Set this project as StartUp project to refer to connection info inside App.config.
Error 2, no key defined for ContactDetail.
Entity Framework has 2 ways to auto define the key field of this class. Look for property name, if name is
1. Id
2. [type] + Id => in this example, it should be ContactDetailId, not CustomerId
Solution, using DataAnnotation, [Key]
Error 3, no relationship definition
Solution, add [ForeignKey(name of associated foreign key)]
After all, the read-only entity data model will generate and show.
沒有留言:
張貼留言