Linq access to databases

Source: Internet
Author: User

In the Models folder under the application, add----new Item---"ADO." NET Entity Data Model--and then select the model content--After the next "Select your database Connection". The database I chose here is sales. Then next, "Select Database Object" You can select the table you want, or view, in front of the table or view you want to tick on it, here I choose the T_userinfo table. I found salesmodel.edmx after the new building.

After clicking on the small triangular symbol in front of SALESMODEL.EDMX, the SalesModel.edmx.Designer.cs file will be displayed under SALESMODEL.EDMX. Open the file and you'll see

One way: public partial class Salesentities:objectcontext

One of the salesentities is the ADO model entity class we created. (Note: I chose the sales database here.) So the name of my entity model class is salesentities. The different database entity model class names you choose are not the same. But it all ends in *****entities.)


Less nonsense.

            using (var datas = new SalesEntities ())            {                var query = from UserInfo in datas. T_userinfo                            where UserInfo. Name==username                            Select New {userinfo. Name};                The Any () method is: Determines whether the sequence contains any elements                if (query = = NULL | |!query. Any ())                {                    //query = = NULL | |!query. Any () means if the data is not queried. Or how to handle a query that does not contain any elements inside the object                 }                                      }


Linq access to databases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.