Weird problem with POCO Adapter for Entity Framework V1

  • Thread starter Thread starter Gutemberg Ribeiro
  • Start date Start date
G

Gutemberg Ribeiro

Hi!
I'm getting one MappingException when try to call context.SaveChanges().
Before I ask for help, let me explain all steps I followed to try use it here.

1. *Create Entity Framework Model Files(CSDL, MSL, SSDL)*
To do it, I just created one custom version of EdmGen utility to make it
easy to attach on project Pre-Compile task. The code is pretty simple, it
receive some command line parameters like outupu path for the files, the
connection string of the source database, the namespace that I want my files
be generated with.
The main method is described bellow:

_private static void Process(string cs, string ns, string em, string cn)
{
try
{
Console.WriteLine();
Console.WriteLine("Connecting to database and retrieving
Entity Store schema...");
var generatorSSDL = new
EntityStoreSchemaGenerator("System.Data.SqlClient", cs, ns);
Console.WriteLine("Generating Store Metadata...");
generatorSSDL.GenerateStoreMetadata();
Console.WriteLine("Writting Store Schema (.ssdl)...");
generatorSSDL.WriteStoreSchema(em + @"\EFModel.ssdl");
Console.WriteLine("Setting Entity Container...");
var storeEntityContainer = generatorSSDL.EntityContainer;

Console.WriteLine("Reading conceptual schema from Entity
Container...");
EntityModelSchemaGenerator generatorCSDL = new
EntityModelSchemaGenerator(storeEntityContainer, ns, cn);
Console.WriteLine("Generating conceptual Metadata...");
generatorCSDL.GenerateMetadata();
Console.WriteLine("Writting Model Schema (.csdl)...");
generatorCSDL.WriteModelSchema(em + @"\EFModel.csdl");
Console.WriteLine("Writting Storage Mapping (.msl)...");
generatorCSDL.WriteStorageMapping(em + @"\EFModel.msl");
Console.WriteLine("Finished!");
Console.ReadLine();
}
catch (Exception ex)
{
Help();
}
}_
2. *Create projects to host the files generated*
I created 2 projects:

ID.Data.Entity.IDCaptura_ - Class Library that will host the Entity model
files and Adapter and Context generated classes on a future step.
ID.Data.Contracts.IDCaptura - Class Library that will host POCO
generated-classes-only on a future step.

I have other projects for other layers like WCF services etc but, it is not
where the problem is.

3. *Setup projects to generate files on pre-build event*

This project *ID.Data.Contracts.IDCaptura* has the followin code into
Pre-build event:

"$(SolutionDir)\Libs\EFPocoClassGen.exe" /conditionalrebuild:true /verbose
/mode:PocoClasses
"/incsdl:$(ProjectDir)..\ID.Data.Entity.IDCaptura\modelSchema.csdl"
"/outputfile:$(ProjectDir)IDCapturaDC.cs" - This just call the EFPocoClassGen
and ask him to create only the dumb POCO Classes.

The project *ID.Data.Entity.IDCaptura* has the following code into Pre-build
event:

"$(SolutionDir)\Libs\EdmGen.exe"
/cs:"server=IDSQL01\ID;database=ID_Captura;integrated security=true;"
/ns:"ID.Data.Entity.IDCaptura.Model" /cn:"IDCaptura" /em:"$(ProjectDir)\" -
This line call my custom EdmGen.exe and pass the parametes to get data from a
SQL Server(/cs:), use a namespace on it(/ns:), set the container name(/cn:)
and create the entity model files in a specific directory(/em:)

"$(SolutionDir)\Libs\EFPocoClassGen.exe" /conditionalrebuild:true /verbose
/mode:PocoAdapter "/incsdl:$(ProjectDir)modelSchema.csdl"
"/outputfile:$(ProjectDir)IDCapturaAdapter.cs"
"/ref:$(ProjectDir)..\ID.Data.Contracts.IDCaptura\bin\$(ConfigurationName)\ID.Data.Contracts.IDCaptura.dll"
/generateProxies:true /autoLazyLoading:true - This Line was used to call Poco
Class Generator util and set some parameters like add the reference to the
POCO Class Library(ID.Data.Contracts.IDCaptura) and the include csdl file
created on previous build step.

"$(SolutionDir)\Libs\EFPocoClassGen.exe" /conditionalrebuild:true /verbose
/mode:PocoContainer "/incsdl:$(ProjectDir)modelSchema.csdl"
"/outputfile:$(ProjectDir)IDCapturaEntities.cs"
"/ref:$(ProjectDir)..\ID.Data.Contracts.IDCaptura\bin\$(ConfigurationName)\ID.Data.Contracts.IDCaptura.dll"
- This last line(in this project) just call the EFPocoClassGen again and
create the PocoContainer Class.

Very well. The creation of everything runs without any error.

4. *Lets use the files generated!*
I just Inserted one entity with InsertOnSaveChanges() and when I run
context.SaveChanges() I got *MappingException with error 2070: GlobalItem*
saying that all my POCO Classes/Entities are defined in both conceptual and
storage models and that it must have an exclusive name...

The weird thing is that since the files are automatic generated by the
utilities, we dont write any code, or define anything in nowhere.

So guys, anyone already got this kind of problem? Any clues on how to fix
it? I can provide more code if you want about my application but, the unique
place where we have entity code is on these DLLs.

Thanks in advice for help!!!

Best regards...

Gutemberg Ribeiro
 
Back
Top