Answered by:
Code-First AND Model-First

Question
-
Hello,
The question is: how to have them work together (Code-First and Model-First) in the same project ? Please, don't ask me why. It is just a crash occuring during an evaluation session, and I'd like to understand.
I'm exploring Entity Framework, beginning by Code First on an existing database. (let me know if anyone need more code or the fulle project)
//Code first CegidContext dbc = new CegidContext(); foreach (Utilisateur utilisateur in dbc.Utilisateurs) { Console.WriteLine("{0,3} {1}", utilisateur.US_UTILISATEUR, utilisateur.US_ABREGE); }
All run perfectly.
Then I add a edmx file from an existing database.
From this point, and with no more code, the preceding code crashes saying he can't found a conceptual model for EF.User: this is an entity for the edmx file, and I only have the preceding Code-First code !
If I try to run the following alone, it is OK
//Database first TESTSEFEntities tEF = new TESTSEFEntities(); foreach (var u in tEF.Users) { Console.WriteLine("{0, 5} {1}", u.Id, u.Login); }
But the following ful code crashes if I don't comment the Code-First part. If I remove from the project the edmx file (and associated foreach) all remaining go well.using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using EF.Entities; namespace EF { class Program { static void Main(string[] args) { //Code first CegidContext dbc = new CegidContext(); foreach (Utilisateur utilisateur in dbc.Utilisateurs) { Console.WriteLine("{0,3} {1}", utilisateur.US_UTILISATEUR, utilisateur.US_ABREGE); } //Database first TESTSEFEntities tEF = new TESTSEFEntities(); foreach (var u in tEF.Users) { Console.WriteLine("{0, 5} {1}", u.Id, u.Login); } } } }
I join the class explorer for understanding:
thierryFriday, August 12, 2011 4:51 PM
Answers
-
hello again,
Il found my answer in here.
The answer is : Impossible to do at this time !
thank you
thierry- Proposed as answer by Patrice ScribeMVP Saturday, August 13, 2011 8:59 AM
- Marked as answer by Alan_chen Thursday, August 18, 2011 3:43 AM
Friday, August 12, 2011 5:22 PM
All replies
-
-
hello,
two different connection string :
<connectionStrings> <add name="CegidContext" connectionString="Server=cosmos2007\SQL090STD01;Database=RD;User ID=ADMIN;Password=***;Persist Security Info=true" providerName="System.Data.SqlClient" /> <add name="TESTSEFEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=SCHMIT-THIERRY\SQL105ENT01;initial catalog=TESTSEF;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings>
CegidContext for code first.TESTSEFEntities for model first.
thierryFriday, August 12, 2011 5:09 PM -
hello again,
Il found my answer in here.
The answer is : Impossible to do at this time !
thank you
thierry- Proposed as answer by Patrice ScribeMVP Saturday, August 13, 2011 8:59 AM
- Marked as answer by Alan_chen Thursday, August 18, 2011 3:43 AM
Friday, August 12, 2011 5:22 PM