In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how Linq uses sqlmetal. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
First of all, let you know about the external mapping file, and then give a comprehensive introduction to Linq's use of sqlmetal.
External mapping file
We can Linq use the sqlmetal command line tool to generate an external mapping file, using the following methods:
1. Start menu-"VS2008 -" VS tool-"VS2008 command line prompt"
2. Enter the command:
D:\ Program Files\ Microsoft Visual Studio 9.0\ VC > sqlmetal / conn:server=xxx; database=Northwind;uid=xxx;pwd=xxx / map:c:\ northwind.map / code:c:\ northwind.cs
3. In this way, we can get a xml mapping file and the entity class code of C # under C disk.
Add the .cs file to the project (put it in the App_Code directory), and then load the mapping file using the following code:
String path = @ "C:\ Northwind.map"
XmlMappingSource xms = XmlMappingSource.FromXml (File.ReadAllText (path))
Northwind ctx = new Northwind
("server=xxx;database=Northwind;uid=xxx;pwd=xxx", xms)
5. Now you can do other work as usual. Linq uses sqlmetal to easily synchronize databases with entities and mapping files. It is also troublesome to delete tables, stored procedures, and then re-add tables from the dbml designer every time you modify the database structure.
Deal with null values
Var count = (from c in ctx.Customers where c.Region = = null select c). Count (); Response.Write (count + ""); var query = from emp in ctx.Employees select emp.ReportsTo; foreach (Nullable r in query) {Response.Write (r.HasValue? R.Value.ToString () + "": "No");}
After code execution, the following SQL is captured and executed:
SELECT COUNT (*) AS [value] FROM [dbo]. [Customers] AS [T0] WHERE [T0]. [Region] IS NULL SELECT [T0]. [ReportsTo] FROM [dbo]. [Employees] AS [T0] Thank you for reading! This is the end of this article on "how Linq uses sqlmetal". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.