A bit with the original database in the use of codefirst far, but always review it, must be comprehensive point.
One, insert two users in the user table (users)
Second, generate the Post interface
MVC generates a lot of interfaces and doesn't use Ajax, which is rarely used in real-world development, just for demonstration purposes.
But no matter what the build, attributes, entity objects, etc. are to be used.
Compile it before you build it.
Three, first try to run
Empty
Should display the user name, displayed as a login name (in fact, it is not expected to be added and modified when the display, not considering the list), delete the tag is also displayed, there is the content, can show the next ...
Four, column display problems
Let the list show the user, just the character set wrong, hey. Just let it show, and then delete the content in the additions and modifications.
The post-run page is as follows:
The login name has not been changed and should be placed behind.
V. Change the login name to the user and put it in the back
Do not find the automatic generation of the sorting order of the characteristics, can only manually drag code, depressed it?!
Column alias Display as:
The system uses the login name not using the display name may be because the login name is in front
Vi. Lessons from Blood
The Auto-generate list box uses the column containing the ID and name, and if there are multiple names, use the preceding, in order to remember it, I dragged the user name to the front:
Seven, re-migration, after the migration of the database in the order of the fields will not change, hey, I forced it also dragged to the front (the list is not based on the search in the database)
Eight, delete the post controller and views in the Post folder, rebuild and run
Nine, you like in front? I'm going to have to get you in the back, you can only install the top one and drag the code again.
Column alias Display as:
The order is really a big problem, fortunately we actually develop the general without it to generate, we build, we can find ways to use features and other methods to solve.
Drag code start is also very simple, select th or TD, drag to the back, press CTRL + E + D, auto-typesetting a bit, I am generally used to press CTRL + E + D + S
Ten, look at our new interface
The order can also be, the content is not multi-line text, should not show the user, the user is we based on the current user login to add.
Changed to multiple lines of text, removing the ntext
Not ntext and Max that's longer, but Max is bigger, do you like long or big? Re-migrate yourself to the database to see it.
Xi. Remove the user, add the new
Remove the following code in creat.cshtml and edit.cshtml
<div class= "Form-group" >
@Html. labelfor (model = model. UserID, "userid", new {@class = "Control-label col-md-2"})
<div class= "Col-md-10" >
@Html. DropDownList ("UserID", String.Empty)
@Html. validationmessagefor (model = model. UserID)
</div>
</div>
Modifying the Controller
Run to see:
Why is there a male topic? Isn't it soft-deleted?
This soft delete is really very troublesome, first go to change it, appear rigorous, of course we also only change this one place:)
Like copy paste No, do you like B or do you like u?
Compile and run to see
OK, that's almost it.
12, remember our post entity object, and the blog is not the same place
The practice also proves that the BOOL system will automatically add the default value False, the other? Check the information tomorrow.
EF6 use Codefirst Total review in the original database (V, generate post page)