Some time ago I reported on LINQ whilst Visual Studio 2008 was still in BETA. On Monday, Nov. 19 2007, Microsoft announced that Visual Studio 2008 and the .NET Framework 3.5 was released to manufacturing (RTM). Since then I am sure many of you have had many hours playing with VS 2008, WPF, Expression Blend, and all that these new products contain. Having finally got my hands on it, and found the time, LINQ was the first stop. So we have a database that we need to run complex queries on where stored procedures just would not be flexible enough. Further to this Inline SQL is an obvious No No, so perfect scenario for a LINQ to SQL implementation.
Deciding that a DBML (Database Markup Language) structure would work best, generating this file, and getting this file to be update-able was crucial. So after some research we found a small, unknown command line application called SQLMetal. This allows you to drop and re-create DBML files, based entirely on a given database.
SqlMetal will always produce a consistent data access layer:
- SQLMetal is a command line tool that can generate the data access layer in seconds.
- SqlMetal will produce either C# or VB.Net code.
- SqlMetal generates a strongly typed data access layer. This is great for reducing runtime error. Now those runtime errors pop up in the development cycle as compile errors, reducing stress on the QA dept, Support dept and upper management, later in the life cycle.
SqlMetal can generate strongly typed interfaces for stored procedures and user-defined functions. From the developer point of view, it is now a complete breeze to call either a stored proc and/or a user-defined function.
To generate source code from SQL database directly, execute the following:
C:Program FilesMicrosoft SDKsWindowsv6.0ABin> SqlMetal /server:baker /database:AdventureWorks /namespace:AdventureWorks /dbml:AdventureWorks.dbml
This creates a DBML file that can be added to your project:
This now gives an entire database structure accessible via LINQ, one thing to be aware of though; ensure you have a solid database design, as SQLMetal will transform you Database design identifying all keys and relationships.
And once you have the database as an object model, you can use LINQ as you wish.
LINQ to SQL uses ADO.NET under the covers but offer several additional benefits:
- Reduces complexity
- Fewer lines of code
- Strong Typing
How Artificial Intelligence and Data Add Value to Businesses
Knowledge is power. And the data that you collect in the course of your business
May
Databricks Vs Synapse Spark Pools – What, When and Where?
Databricks or Synapse seems to be the question on everyone’s lips, whether its people asking
1 Comment
May
Power BI to Power AI – Part 2
This post is the second part of a blog series on the AI features of
Apr
Geospatial Sample architecture overview
The first blog ‘Part 1 – Introduction to Geospatial data’ gave an overview into geospatial
Apr
Data Lakehouses for Dummies
When we are thinking about data platforms, there are many different services and architectures that
Apr
Enable Smart Facility Management with Azure Digital Twins
Before I started writing this blog, I went to Google and searched for the keywords
Apr
Migrating On-Prem SSIS workload to Azure
Goal of this blog There can be scenario where organization wants to migrate there existing
Mar
Send B2B data with Azure Logic Apps and Enterprise Integration Pack
After creating an integration account that has partners and agreements, we are ready to create
Mar