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 Query
- What is the quickest way to query a database with LINQ?
- Linq - What is the quickest way to find out deferred execution or not?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- What is the best way to cast each item in a LINQ to Entities query to an interface?
- What is the best way to query a database for records within n miles of a zip code?
- What is the easiest way to save a LINQ query for later use?
- What is the return type for a anonymous linq query select? What is the best way to send this data back?
- What is the preferred way to interact with WMI using LINQ
- What is the proper way to use linq Group operators to Flatten Query Results
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- What is the correct way to Take() X-number of records with LINQ but find out if there are more
- LINQ to SQL - is there a way to get a 'preview' of the database with changes made to a context?
- What is the best way to write a two column query in LINQ to Entity 6? And save the results to two different variables?
- What SQL query or LINQ code would get the following data?
- How can I query a database with LINQ when the column is a number but I have a string in the WHERE?
- LINQ query returns way more results than in the entire database
- What is the easiest way to return the first set of linq query properties as optional strings?
- Is there a way to use linq query with DateTime and a string working together in the same request?
- What is the easiest way to compare DateTime in linq with sql server ce?
- What is the correct way to use Linq to reference the table you instantiate with your ViewModel as a list to generate a list of 'SelectListItems'?
- Get the Value of WPF Listview rows and compare them with database field using Linq query
- What is the easiest way to find the LINQ statement for a SQL statement
- Why didn't the LINQ designers stick with using the way sql is written today?
- What is the difference between LINQ query expressions and extension methods
- What is the proper way to do a C# LINQ Where/Select in C++?
- why .ToList().Distinct() throws error but not the .Distinct().ToList() with linq query
- What is the best way to create strongly typed LINQ queries from some given strings, via reflection
- The best way to build Dynamic LINQ query
- LINQ Query to insert data into the database
- LINQ to XML: What is the most effective way to move nodes up and down
More Query from same tag
- Create Home Page presents multiple types of objects and the objects order by date with ASP.Net
- LINQ Query incredibly slow - why?
- Linq casting between types
- Get a list of date Ranges from a list Of dates
- Linq query with list of flags
- how to get the sql table name from table type in linq
- How to create column and row wise json structure?
- Linq to SQL method defaults to ISingleResult
- Gettings grouped sums from related tables into linq query columns
- LINQ: Where() ignore simple false condition
- Is Queryable.OrderBy unstable for SQL Server database?
- linq to sql join on multiple columns using lambda error
- In Entity Framework Core, with one query, how do I select objects by the order of a parent object?
- Aggregate function. Sequence of steps
- What is the best way to remove all instances from a Dictionary?
- Join multiple tables when using a generic repository in C#
- Difference between PredicateBuilder<True> and PredicateBuilder<False>?
- Why doesn't Enumerable.Cast<> use my conversion operator?
- Linq query in custom class
- Entity Framework: M-to-n: Read a linked entity from a list
- Are subqueries in LinqToSql guaranteed to be in the same order as their parent?
- how to read the last inserted field with linq
- How to see the SQL query for my lambda expression
- Taking objects from list only if not empty
- LINQ Query in DataTable
- Hide some object fields before outputing?
- Convert LINQ to List<T> to Python 2.7
- Looking for a list of items in a query
- LINQ query - needs to change a field name
- the promote method returned an invalid value for the distributed transaction only in azure