TAILIEUCHUNG - Lập trình .net 4.0 và visual studio 2010 part 30

Trong các phiên bản trước của EF, lĩnh vực trọng điểm về các thực thể nước ngoài đã được ẩn từ nhà phát triển trong mô hình tạo ra. Nhà phát triển đã được dự kiến sẽ truy cập vào các thực thể liên quan trực tiếp thay vì truy vấn các lĩnh vực trọng điểm nước ngoài. Điều này có thể có nghĩa là làm cho một số cơ sở dữ liệu truy vấn bổ sung để tham gia các thực thể và viết một số mã tẻ nhạt | CHAPTER 8 ENTITY FRAMEWORK -- Creating all Primary Key Constraints -- Creating primary key on CustomerID in table Customers ALTER TABLE dbo . Customers WITH NOCHECK ADD CONSTRAINT PK_Customers PRIMARY KEY CLUSTERED CustomerID ASC ON PRIMARY GO -- Creating primary key on AddressID in table Addresses ALTER TABLE dbo . Addresses WITH NOCHECK ADD CONSTRAINT PK_Addresses PRIMARY KEY CLUSTERED AddressID ASC ON PRIMARY GO -- Creating all Foreign Key Constraints -- Creating foreign key on CustomerCustomerID in table Addresses ALTER TABLE dbo . Addresses WITH NOCHECK ADD CONSTRAINT FK_CustomerAddress FOREIGN KEY CustomerCustomerID REFERENCES dbo . Customers CustomerID ON DELETE NO ACTION ON UPDATE NO ACTION GO 22. Click Finish. 23. You will receive a warning Figure 8-21 click Yes. Figure 8-21. Warning displayed on generated T-SQL That s it you can now run this SQL on your database and use the EDM in the standard way. Foreign Keys In previous versions of EF foreign key fields on entities were hidden from the developer in the generated model. Developers were expected to access the related entity directly instead of querying foreign key fields. This could mean making some additional database queries to join entities and writing some tedious code. 201 CHAPTER 8 ENTITY FRAMEWORK For example in our code we might be creating a UI for managing FilmShowings. It would be a lot easier if when creating a new film showing we could just set the related FilmID property FilmID In EF4 you can. It may be worth questioning whether you should be working this way but I think on the whole it avoids additional database queries. Code Only POCO One of the biggest complaints about Entity Framework v1 was that unless you wanted to write some complex code you had to work with the generated classes and associated data context. This dependence on Entity Framework made it harder to perform unit testing create n-tier applications and work with third-party systems. A number of methods

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.