Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a new ADO.NET Entity project

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is mainly about "how to build a new ADO.NET Entity project". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build a new ADO.NET Entity project.

The insertion of this type of data is different from the general basic SQL type, but programmers working on the .net 3.5 platform do not need to think too much about the specific code to access the database. We can choose ADO.NET Entity Framework and Linq to SQL. Here we take the former as an example. The method is briefly introduced as follows:

New in the project, select ADO.NET Entity Data Model, establish a connection to the database according to the wizard, and select the table images just established in the database according to the wizard. After the wizard ends, an edmx type file will be added to the project. The automatically generated entity class diagram will open in the default interface. All the tables we select in the wizard will correspond to an entity class with the same default name as the data table. The entity class corresponding to images here is also images, but it will cause ambiguity if it is used by default, and we need to modify it manually.

Click on the images class to change the Name attribute to image,Entity Set Name in the properties dialog box, you can change it to imageSet or leave images unchanged to represent the image collection, and the corresponding class name in the entity class diagram becomes image after ADO.NET Entity. This assumes that the database where the images are stored is named XXX, then the generated management class, which we use most frequently later, is called XXXEntities.

Save the picture to the SQL server database, first declare a variable of type image, call it img, image img = new image ();, and then create a XXXEntities object, XXXEntities XXX = new XXXEntities ()

Put an Image control in the page showImage.aspx, named Image1, because the picture is a binary file taken from the database, so unlike when using the file ADO.NET Entity system, the picture has its own URL, we can directly set its URL as the path of the picture in the site, the solution is as follows.

Create another asp.net page getImage.aspx dedicated to providing pictures, its function is only to read pictures from the database, use Response.BinaryWrite () to output the image data stream, then you may have thought of, we set the URL of image1 to the above getImage.aspxADO.NET Entity, if you need to select based on information such as the id of the picture, we provide an additional id parameter for the asp.net page.

To read an image, still use the above XXX entity management class, such as getting an image with an id of 1. The code is as follows:

Int id = int.Parse (Request.QueryString ["id"])

Image img = XXX.imageSet.Where (I = > i.ID = = id) .First ()

Response.BinaryWrite (img.imageFile)

Source: DIY tribe (http://www.diybl.com/course/7_databases/database_other/20090816/168697.html))

At this point, I believe you have a deeper understanding of "how to build a new ADO.NET Entity project". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report