2013年6月2日 星期日

Entity Framework–Model First, Part 2 (Generate database schema)

Before we generate database schema, we can do 2 things

1. Validate our model

2. See our model in XML format

 

1. Validate our model, right-click on any space –> Validate

image

The Error List will pop-up, but actually there is no error but 2 warnings. It is because our database hasn’t been created and the tables are not exist.

image

 

2. See our model in XML format, right-click on SalesOrder.edmx –> Open With…

image

Choose XML (Text) Ediror –> click OK

image

Since the edmx file can only been open by once (in either design mode or XML text mode). Click Yes to close current design mode.

image

There are 3 major contents in the file,

1. SSDL content

2. CSDL content (expend in next picture)

3. C-S mapping content

image

CSDL content part, if we point to that, it will show an Error 11007: Entity type ‘xxxx’ is not mapped. It’s the same message in previous Validate action above.

image

 

Now we can re-open our model design window, and right-click on any space –> Generate Database from Model…

image

Make sure we are connenct to right destination

image

If the database we are going to connect is not exist, click Yes to attempt to create it.

image

Click Next with the right connection string

image

The DDL file will be generated for our review, and we can click Finish to save it

image

Now we will see the file  xxx.edmx.sql open

image

沒有留言:

張貼留言