Beginner C # and MVC some tips, detours, summaries, and lessons (2)--About the entity Framework

Source: Internet
Author: User

---restore content starts---

After watching a bunch of video tutorials, I feel basically familiar with it and can do it ..... Because the best way to learn is to practice ....

So I'm going to start from the website and choose MVC between WebForm and MVC because it feels big on ... Also more flexible

So I bought two books, "ASP. 4 Advanced Programming (4th Edition)" and "ASP 4 Web Programming", and there were a group of friends in the group asking, why buy two ... In fact, this is a habit ... For starters, the first thing to know is that this is probably something .... The author of the book is different, the focus of the introduction is different, buy two to complement the ...

MVC also probably looked at, at least the basic controller, try Ah, and the whole process is familiar with the almost, ready to do ....

Let's start by talking about the problems encountered in choosing a database access technology .....

Look at the tutorial, basically the database is done with EF ... So also followed the use of Microsoft's official production on the tall entity Framework ....

Codefirst God horse too far, so first open SQL Server to build a library, and then write model ... Then the cheerful start ...

And then, without an accident, you're in trouble.

1. Before a thorough understanding of the completely object-oriented database design approach, the idea is confined to the SQL era (after all, many years of writing SQL statements), which leads directly to the unreasonable database tables and model design

Then there is the model (omitting some extraneous fields)

Menu ID, parent menu ID, menu name, parent menu name ...

When used, Parentcode gets the menuname of the parent menu to ParentName

     Public classMenu {[Key] Public intmenucode{Get;Set; }  Public intParentcode {Get;Set; }  Public stringMenuName {Get;Set; } [Notmapped] Public stringParentName {Get;Set; }

So there is the self-connection (oneself join oneself) query code ....

            varquery = fromAinchDB. Menus Join BinchDB. Menus on A.parentcode equals b.menucode into LG fromBinchLg. DefaultIfEmpty ()Select NewSdou. Models.Staff.Menu {Menucode=A.menucode, MenuName=A.menuname, Parentcode=A.parentcode, ParentName= b = =NULL?"": B.menuname};

Splat a run, the problem comes again ....

My model is clearly placed in the Models.Staff.Menu, when the EF is not going to give me the full name of the Dal, and then tell me I can't relate the entity or what .... In short, it is automatically give me the name space to change .....

For the novice of me, Baidu Google tinkering half a day did not solve the problem ...

Backstage Help the Great God, the great God said, you see this is a problem, not the problem of EF, but your own thinking problems .... This is in holding the EF to write SQL .... (In fact, I would like to say that, of course, I can only sql) ..... Then the great God said, if the beginner has no object-oriented design ideas, go back to using SQL ....

Since the great God's guidance, I do not struggle to find out where the problem is, even if the namespace problem is fixed, later with EF will definitely encounter more problems .... The simple queries that connect to themselves are uncertain, not to mention complex queries that span multiple tables ....

So the parties to help, Baidu Google some know a few lightweight micro ORM framework ... Petapoco,dapper,fluentdata,datarabbit these several recommended more, sometimes no choice is OK, take to use, but there is a choice when it will be more difficult to decide ....

So, there is this Bo asked http://q.cnblogs.com/q/65659/let the great God help me make a choice ....

The final result is to discard EF and enable dapper

Beginner C # and MVC some tips, detours, summaries, and lessons (2)--About the entity Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.