Entity Framework Connection string

Source: Internet
Author: User
Tags connectionstrings

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data.Entity;namespacecodefirstnewdatabasesample{ Public classBlog { Public intBlogId {Get;Set; }  Public stringName {Get;Set; }  Public VirtualList<post> Posts {Get;Set; } }     Public classPost { Public intPostID {Get;Set; }  Public stringTitle {Get;Set; }  Public stringContent {Get;Set; }  Public intBlogId {Get;Set; }  Public VirtualBlog Blog {Get;Set; } }     Public classBloggingcontext:dbcontext { PublicBloggingcontext ():Base("Name=blogcontext") { }          PublicDbset<blog> Blogs {Get;Set; }  PublicDbset<post> Posts {Get;Set; } }  classProgram {Static voidMain (string[] args) {            using(vardb =NewBloggingcontext ()) {                //Create and save a new BlogConsole.Write ("Enter a name for a new Blog:"); varName =Console.ReadLine (); varBlog =NewBlog {Name =name}; Db.                Blogs.add (blog); Db.                SaveChanges (); //Display all Blogs from the database                varquery = fromBinchdb. Blogs byB.nameSelectb; Console.WriteLine ("All blogs in the database:"); foreach(varIteminchquery) {Console.WriteLine (item.                Name); } Console.WriteLine ("Press any key to exit ...");            Console.readkey (); }     } }}

Add a service-based database

 Public bloggingcontext ()             Base ("name=blogcontext") {}  //strings Attached

Or

 Public bloggingcontext ()             Base ("blogcontext") {}  //  strings attached

or wait.



App. Config Add content

  <connectionStrings>    <add name="blogcontext" connectionstring= " Data source= (LocalDB) \v11.0; Attachdbfilename=d:\schoolwork\ software \ Database Connection \codefirstnewdatabasesample\codefirstnewdatabasesample\blogdatamdf.mdf ; Integrated security=true"      providerName="System.Data.SqlClient " />  </connectionStrings>

String source

Entity Framework Connection string

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.