Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

// This is might be because we have a DbFirst DbContext, so let's try it out. #7

Closed
mikemichaelis opened this issue Apr 20, 2017 · 6 comments

Comments

@mikemichaelis
Copy link

mikemichaelis commented Apr 20, 2017

From MetadataGenerator/Program.cs:

/// When using a DbFirst approach EF thwros two kind of exceptions:
/// 1. InvalidOperationException is there is no connection string for the DbContext we are working on.
/// 2. UnintentionalCodeFirstException if it finds the connection string for the DbContext.
/// UnintentionalCodeFirstException inherits from InvalidOperationException

The only way I can get a DbFirst EF 6.0 model to produce Metadata is to uncomment:

        catch (InvalidOperationException iex) // This is might be because we have a DbFirst DbContext, so let's try it out.
        {
            try
            {
                return EFContextProvider<object>.GetMetadataFromDbFirstAssembly(type.Assembly, Options.ResourcePrefix);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception was thrown while processing the dbfirst assembly {0}. {1}", type.Assembly.FullName, ex);
            }
        }

The InvalidOperationException thrown does have the message:

"No connection string named 'TIPS_Corn_DevEntities' could be found in the application config file."

as is indicated in the /// 1 comment above, however the connection string does exist and is properly named within the specified .dll.config. Properly catching and executing

GetMetadataFromDbFirstAssembly()

will properly generate the metadata.

Why is this code commented out?

Thanks,
Mike

@mikemichaelis
Copy link
Author

Locally I have modified MetadataGenerator to accept a command line argument to allow for metadata generation of EF 6 DbFirst DbContext.

I would also suggest better handling when MetadataGenerator is used with an EF 5 DbContext as currently nothing is written and nothing is logged to the console. Maybe it is documented somewhere that MetadataGenerator only works with EF 6? The reason EF 5 does not work is there is a failure loading the EF 5 libs in t.IsSubclassOf(typeof(DbContext)) of GetDbContextTypesFromAssembly()

Please at least better document MetadataGenerator as after reading a lot about BreezeJS and getting quite excited, I hit a brick wall with the very first step in the process, generating metadata from my existing EF models (EF 5 & DbFirst). Not a very good first start. I'm glad I worked through this, as I'm still excited to use BreezeJS, but I must admit my initial frustration.

<< mike

@mikemichaelis
Copy link
Author

mikemichaelis commented Apr 21, 2017

One more thing, your existing docs for MetadataGenerator are wrong. The docs show the parameters with the full parameter name but only a single leading dash. Ie

-native

should be

--native OR -n

Regardless neither of those actually work, even in temphire.angular - edit package.json/metadata:

"metadata": ".\tools\bin\MetadataGenerator.exe -i ..\..\BreezeTest\test-model\notModel\bin\Debug\notModel.dll -o metadata.json -n"

Produces nothing as does --native. There is a race condition between when you launch the Node Process to convert the json and you delete the source json itself. IE

ConvertCsdlToNative(tempFileName, fileNameFullPath); // does not wait for completion
File.Delete(tempFileName);

<< mike

@marcelgood
Copy link
Collaborator

marcelgood commented Apr 21, 2017

Sorry about your experience. The Breeze Tooling repo is a free tool that we put out there as a convenience to generate the TypeScript classes for Breeze entities as apposed to having to code them manually. It's intention is not to generate the metadata. It spits out the metadata in order to use it for the TypeScript class generation, but you don't need this tool to generate the metadata. Breeze can directly fetch the Metadata from an EF back-end. It definitely doesn't support EF5. EF5 is old and has been outdated for a while now.

As with Breeze itself, this tool is open source and free to use. If it doesn't work for you or you find bugs, you are free to contribute any fixes. We use the tool quite successfully for own projects. Once in a while we run into an issue and fix it.

We contribute things like this to the community as we think somebody might find it helpful, but this is not a commercial product nor are we charging money for it, so use it at your own risk. We do offer Breeze support and consulting if you prefer a more commercial relationship with us and need help with the tooling.

@mikemichaelis
Copy link
Author

If you love your code like I do, then just try to see it from my perspective.

I have an DbContext (EF5). Try to generate typescript classes. Fail. Recreate DbContext in EF6. Try to generate typescript classes. Fail. Download source of MetadataGenerator. Find a few small issues that caused me a lot of headaches. Get a response from the repo team basically saying "it's free, what do you expect".......

If you open the MetadataGenerator repo to me I'll PR my small changes as you suggested.

<< mike

@marcelgood
Copy link
Collaborator

I'm gonna close this issue. We really don't need such a negative attitude here. I understand that this is coming out of frustration, and there are probably issues in the tool. I'm not sure why you would still use EF5. Performance is worse than EF6 etc and it's a straight forward upgrade to EF6.

I will take a look at why the tooling is failing in temphire.angular. It's most likely because other libraries have been updated with breaking changes. I didn't have to re-generate the entities for temphire in a while.

We appreciate the community pointing out issues with the code that we publish, but please don't be rude.

@marcelgood
Copy link
Collaborator

marcelgood commented Apr 21, 2017

One final update. The tooling seems to work fine in temphire. The final metadata is actually generated by tsgen-core.js and is output in the form of metadata.ts next to the entity classes. The native option in the .exe was actually an experimental option, and I think there is something missing. It forks a node process to do the conversion.

Here's my run against an empty entities folder. There's one known bug that we haven't fixed yet. The output folder must exsist, otherwise it fails. If you delete the entire entities folder it will fail, because the tool doesn't create the folder.

C:\Workspace\Frameworks\temphire.angular\TempHire>npm run metadata-entities

> [email protected] metadata-entities C:\Workspace\Frameworks\temphire.angular\TempHire
> npm run metadata && npm run entities


> [email protected] metadata C:\Workspace\Frameworks\temphire.angular\TempHire
> .\tools\bin\MetadataGenerator.exe -i ..\DomainModel\bin\Debug\DomainModel.dll -o metadata.json

MetadataGenerator -i ..\DomainModel\bin\Debug\DomainModel.dll -o metadata.json

> [email protected] entities C:\Workspace\Frameworks\temphire.angular\TempHire
> node ./tools/tsgen.js

Generating typescript classes...
Input: C:\Workspace\Frameworks\temphire.angular\TempHire\metadata.json
Source: C:\Workspace\Frameworks\temphire.angular\TempHire\app\core\entities
Output: C:\Workspace\Frameworks\temphire.angular\TempHire\app\core\entities
CamelCase: true
Injected base class: EntityBase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants