The previous article discussed how to use the NEWID () Random Function in ms SQL. We will not discuss it here. in NET, LINQ is actually a profound combination of MSSQL database and object-oriented thinking. I personally understand it as an ORM. I have no in-depth research on ORM. I only understand the ideas here, also. Sorry, it seems that there are still a lot of things you need to learn by yourself.
First, you must add the following code to the DBML file to map the relational functions. In fact, the code is added to the DBML background code file. In the DESIGNER. CS file,
Code
1 [Function(Name = "NEWID", IsComposable = true)]
2 public Guid NEWID()
3 {
4 return ((Guid)(this.ExecuteMethodCall(this,
5 ((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue));
6 }
The above code maps to the NEWID () system function in MSSQL.
Then, call the code file in your page FILE or form file. See the following CODE:
Code
private void bindGridview()
{
db = new NorthWindDataContext();
var result = (from c in db.Customers orderby db.NEWID() select c).Take(10);
GridView1.DataSource = result;
GridView1.DataBind();
}
The preceding figure shows how to use NEWID in LINQ. Remember, if NEWID is the function name generated by you in the DBML code file, it must be capitalized when you call it automatically, this is defined by yourself, and does not have to have the same name as NEWID in MSSQL. You can write it as public Guid returnMssqlNewid () and so on, depending on how you can flexibly set the name, it is easier for others to read and call the API.
This article is written here. I hope you can make a lot of mistakes. A lot of communication.