In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to create a Linq database, the article is very detailed, has a certain reference value, interested friends must read it!
Create a Linq database
The ◆ CreateDatabase method is used to create an Linq database on the server.
The ◆ DeleteDatabase method is used to delete the database identified by the DataContext connection string.
The name of the database can be defined in the following ways:
◆ if the database is identified in the connection string, the name of the connection string is used.
◆ uses its Name attribute (Property) as the name of the database if there is a DatabaseAttribute attribute (Attribute).
◆ if there is no database tag in the connection string and a strongly typed DataContext is used, the database with the same name as the DataContext inheritance class is checked. If you use a weakly typed DataContext, an exception is thrown.
If you have created a DataContext by using a file name, a database corresponding to that file name is created.
We first use entity classes to describe the properties of the structure of relational database tables and columns. Then call the CreateDatabase method of DataContext, and LINQ to SQL will construct a new database instance using our defined entity class structure. You can also use CreateDatabase with SQL Server by using an .MDF file or by using only the directory name (depending on the connection string). LINQ to SQL uses a connection string to define the Linq database to be created and the server that serves as the location for the database creation.
Having said so much, let's illustrate it with an example.
First, we create a new NewCreateDB class to create a new database called NewCreateDB.mdf, which has a Person table with three fields, PersonID, PersonName, and Age.
Public class NewCreateDB: DataContext {public Table Persons; public NewCreateDB (string connection): base (connection) {} public NewCreateDB (System.Data.IDbConnection connection): base (connection) {}} [Table (Name = "Person")] public partial class Person: INotifyPropertyChanged {private int _ PersonID; private string _ PersonName; private System.Nullable _ Age Public Person () {} [Column (Storage = "_ PersonID", DbType = "INT", IsPrimaryKey = true)] public int PersonID {get {return this._PersonID;} set {if ((this._PersonID! = value)) {this.OnPropertyChanged ("PersonID"); this._PersonID = value; this.OnPropertyChanged ("PersonID") } [Column (Storage = "_ PersonName", DbType = "NVarChar (30)")] public string PersonName {get {return this._PersonName;} set {if ((this._PersonName! = value)) {this.OnPropertyChanged ("PersonName"); this._PersonName = value; this.OnPropertyChanged ("PersonName") } [Column (Storage = "_ Age", DbType = "INT")] public System.Nullable Age {get {return this._Age;} set {if ((this._Age! = value)) {this.OnPropertyChanged ("Age"); this._Age = value; this.OnPropertyChanged ("Age");} public event PropertyChangedEventHandler PropertyChanged Protected virtual void OnPropertyChanged (string PropertyName) {if ((this.PropertyChanged! = null)) {this.PropertyChanged (this, new PropertyChangedEventArgs (PropertyName));}
A piece of code first creates a Linq database, and after calling CreateDatabase, the new database exists and accepts general queries and commands. Then insert a record and query it. * delete this database.
The above is all the contents of the article "how to create a Linq database". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.