We continue post series about Entity Framework usage. We consider the following questions in this article:
- MS SQL Server and Oracle – how to use both in one EF project?
- DDL is generated with wrong keywords.
- What is the difference between .edml and .edmx models?
- Why setting the StoreGeneratedPattern attribute to “Identity” or “Computed” in Visual Studio 2010 does not work as expected?
- How can I avoid loading an entire child collection?
1. MS SQL Server and Oracle – how to use both in one EF project?
Issue:
Solution:
- Create a copy of your .edmx file, set a valid Oracle connection for it, and run the Generate Database from Model wizard. As a result you will obtain a new valid EF Oracle model
- Change the Metadata Artifact Processing property to CopyToOutputDirectory for both models
- Change the connection strings accordingly (pointing to the same .csdl. .msl. and different .ssdl resources)
Basically, that’s all.
As for the users’ feedback, Paul Reynolds, one of our users, has created series of posts based on his experience in a similar task:
Preparing for Multiple Databases
Database Agnostic LINQ to Entities
If you are interested in Model First, take a look at this post by Vagif Abilov. Don’t miss our comment.
2. DDL is generated with wrong keywords.
Issue:
Solution:
3. What is the difference between .edml and .edmx models?
Issue:
Solution:
As for Oracle cursors, read our blog-article – Working with Oracle cursors and stored procedures in Entity Framework.
There is no possibility to handle this situation in design time using Entity Data Model designer.
4. Why setting the StoreGeneratedPattern attribute to “Identity” or “Computed” in Visual Studio 2010 does not work as expected?
Issue:
Solution:
5. How can I avoid loading an entire child collection?
Issue:
var parents = from p in context.Parents select p; foreach (var parent in parents) { var children = from c in parent.Children select new { c.ID, c.Name }; }
The issue is the fact that the generated SQL I can see in OracleMonitor is too agressive. It loads the complete child entity, and only after that the LINQ to Objects filtering occurs. Is it a bug or do I miss something?
Solution:
When you are calling parent.Children, the EF Lazy Loading mechanism loads the entire collection, and the select new clause is only a LINQ to Objects query, and is executed in memory. As a workaround you can use, for example, the following syntax:
var parents = from p in context.Parents select p; foreach (var parent in parents) { var children = from c in context.Children where c.ParentID == parent.ParentID select new { c.Id, c.Name }; }
This statement will produce the query you expect.
We hope this material will be useful for you. Please provide your feedbacks and suggestions in comments to article.
Tanx for the identity bit in SSDL
Really helped alot