In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use LINQ to SQL data table", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use LINQ to SQL data table" this article.
DbConnection is used in LINQ to SQL data tables instead of SQLConnection, which theoretically supports all data, but support for some databases may not be very good. For example, paging, SQL Server 2000 Magi SQL Server 2005 SQL Server 2008 data, the code that uses LINQ is not the same, but ACCESS and SQL Server 2000 are close, so you can use SQL Server 2000Provider directly. After looking up some data, we can see that if we have that database provider, we can support this kind of database. Also read the dbLINQ 0.8 support for different databases of the source code, but their limited ability to write an ACCESS, or use the official bar. Here's how to do it.
In fact, he is not too troublesome, just change the code in the * .designer.cs file. Because ACCESS does not support dbo, and LINQ to SQL data tables are preceded by dbo. Prefix, [Table (Name= "dbo.wjk3")], dbo. Get rid of it, otherwise, it will prompt you that you can't find the dbo database. You've taken a lot of detours on this point. Add [Provider (typeof (System.Data.LINQ.SQLClient.SQL Server 2000Provider))] to SQL Server 2000Provider on top of public partial class DDataContext: System.Data.LINQ.DataContext, otherwise the first in LINQ cannot be used, and paging cannot be used, because it defaults to SQL Server 2008Provider.
This is very important, so far, basically solved the use of LINQ to ACCESS, but there is still a problem, read a record from the database, modified and updated with SubmitChanges (), indicating an error, can not be modified, error content: the row cannot be found or the row has been changed. You can use some custom methods to implement the update, using ExecuteCommand () to directly execute the update SQL statement. Feel that the tracking of LINQ to SQL data table, if not applicable to SubmitChanges () update, tracking may reduce the system energy, add and delete also depend on tracking, if you do not use tracking, but also expand the add, delete methods.
Public partial class dbgame
{
Public IQueryable Find (TEntity obj) where TEntity: class
{
/ / get all the property information
PropertyInfo [] properties = obj.GetType ().
GetProperties (BindingFlags.Public | BindingFlags.Instance)
/ / construct the initial query
IQueryable query = this.GetTable () .AsQueryable ()
/ / traverse each property
Foreach (PropertyInfo p in properties)
{
If (p! = null)
{
Type t = p.PropertyType
/ / add object,Binary, and XDocument, and support the mapping of sql_variant,imager and xml.
If (t.IsValueType | | t = = typeof (string) | | t = = typeof (System.Byte []))
| | t = = typeof (object) | | t = = typeof (System.Xml.Linq.XDocument) |
| | t = = typeof (System.Data.Linq.Binary))
{
/ / it is considered a condition if it is not for null
If (p.GetValue (obj, null)! = null)
{
If ((ColumnAttribute) (p.GetCustomAttributes (typeof (ColumnAttribute))
True) [0]) .IsPrimaryKey & & Convert.ToInt32 (p.GetValue (obj, null)) = = 0)
{
}
The above is all the contents of the article "how to use LINQ to SQL data sheet". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.