score:2
Look at the end of the Form1.cs source file, the LINQ to SQL database is declared using attributes:
[Database(Name = "AdventureWorks")]
public class AdventureWorks : DataContext
{
//public Table<DirInfo> DirectoryInformation;
public AdventureWorks(string connection) : base(connection) { }
public Table<DirectoryInformation> DirectoryInformation;
}
[Table(Name = "DirectoryInformation")]
public class DirectoryInformation
{
[Column(DbType="varchar(50)")]
public string DirectoryName;
[Column(DbType = "varchar(255)")]
public string DirectoryDescription;
}
Providing the settings with the project define a connection string, this is all you need for a simple mapping of the DirectoryInformation type to the DirectoryInformation table in the AdventureWorks database.
score:1
Oh, absolutely you can use vanilla objects with LINQ-to-SQL; you don't even need to subclass DataContext
- but you do need to tell it about your model. This is often done with attributes on members (for columns) and types (for tables), but can also be done with an external mapping file (xml). I wonder if they are just over-abbreviating for simplicity... for example, I suspect that the table should be a property:
public Table<DirectoryInformation> DirectoryInformation {
get { return GetTable<DirectoryInformation>(); }
}
The whole "dbml" thing is just there as a designer tool to help you generate the classes; the important code is just decoracted classes (with some conventions on things like navigation properties to make life simper to use). That said, for "quickest": use the designer.
Source: stackoverflow.com
Related Articles
- What is the quickest way to query a database with LINQ?
- Linq sub query when using a repository pattern with EF code first
- what is difference between linq query with Take and without?
- What means a combined All with Any LINQ query
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Can't add a new record with an integer value into database by using linq from code C#
- Avoiding repeating code with Linq query + optional params
- query MS access database with LINQ in c#
- What SQL query or LINQ code would get the following data?
- Searching for multiple strings using single database query with entity framework and LINQ
- how to write a Linq query with a EF code first Many to Many relationship
- What do i use with LINQ in order to READ database instead of SqlDataReader?
- Issue with querying database using LINQ query to bring list of DTO
- Many to Many database query with LINQ
- What is wrong with this LINQ query
- How can I query a database with LINQ when the column is a number but I have a string in the WHERE?
- Can someone advise me what wrong with my Type or linq query
- What is a clean LINQ query to get items with no child items?
- Linq query through database with every word
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- Query with linq from database
- Using a LINQ query to populate a combo box with data from an access database
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Assign/Compare DateTime value from Database with DateTime value from C# in Linq query
- LINQ query with Inner Join not working when multiple records are added to database
- Performing a Sum() with LINQ query on database
- How to create a database query with LINQ to erase rows by having a list of ID's and by avoiding loops
- Get the Value of WPF Listview rows and compare them with database field using Linq query
- Linq query with nullable sum
- What does this C# code with an "arrow" mean and how is it called?
- Can I streamline this LINQ query
- Calculate total number of threads in the operating system(Windows/Linux)
- Multiple Group data
- How do I iterate an IGrouping<T> Interface?
- Cannot implicitly convert type 'System.Collections.Generic.List<System.Linq.IGrouping<int, x>>' to 'System.Collections.Generic.List<x>'
- How to Remove Range after Add Range in same operation
- LINQ to SQL for tables across databases. Or View?
- Generic way of creating XML files in C#
- LINQ to Entities does not recognize the method,and this method cannot be translated into a store expression
- Linq to create a csv string for some values stored in an array of object using c#
- LINQ query in Entity framework 6
- List<string> get item that starts with Name= using LINQ
- Search words in list of structs and get all words with postfix
- Why Standard Extension Method on IEnumerables
- C# For Loop with LIST using LINQ
- Should I be using a Dictionary or List with a linq search?
- Selecting a record where value falls between two strings in LINQ2SQL
- LINQ Concat child lists in a list
- Datatable group by having c#
- Querying XML and updating certain elements