Simple way to extend the default ApplicationDbContext in asp mvc5 using Ef6 Code First - asp.net-mvc-5

When i run the entity framework Reverse Engineer Code First in an asp mvc project, it runs fine and generates all the mapping and poco classes, but i now have two context and conflicting classes in both the ApplicationDbContext and the new Auto Generated DbContext.

When generating EF Classes using Code First from Database, often there are more steps as the generated code is not always exactly as you want. I typically rename all files to "EntityNameDAO" I then right click refactor all classes to "EntityNameDAO" to match the file name appropriately.
After this, you will typically find that you have additional or less needs or perhaps even circular dependencies in the json result from these generated classes. To deal with this, I create specific domain objects for each objective EntityName_SpecificUseCase.
You will notice I use EntityName"AdditionalData" so that the alphabetic sorting keeps each of my entities next to eachother and I can verify I have the right flavors for each entity quickly and easily.
To deal with the circular json, you will need to add this code to your appconfig.cs:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling =
Newtonsoft.Json.PreserveReferencesHandling.All;

Related

textual syntax for domain models

we have domain models described in some xml format. Given the domain models I want to generate tooling that helps the testers/domain experts to express data in text (and a domain specific test framework later). IDE support is mandatory (IDEA or eclipse).
say, i have this pseudo model
User
fn string 120 chars mandatory
ln string 120 chars mandatory
address not-mandatory
Address
street mandatory
city mandatory
A typical usage scenario:
user opens the IDE
creates a new file
when content assist invoked, should give options 'user', 'address' etc
If I choose user, furthur ctrl-space should give 'fn', 'ln', 'address' as options.
I know this can be done by xtext or jetbrains mps etc. But, I want to understand which technology lends for the following requirements.
the models are fed to the system at run time (new, updates, deletes etc).
so, I cannot have static set of grammars. How can I structure it so that the model/property assist is resolved at run time or at least the grammar is generated (may be a part of it)
when I am working with one set of 'grammars' , if I point my target server to a different version (which may have different set of models) , I want the editor validate my existing files and flag errors.
I get the data files in xml, text or via server lookups.
It is very important for me to transform the models into some other format or interpret them in java/groovy.
for ex,
I may have the following data file
user {
fn : Tom
ln : Jill
hobby : movies
}
but, when I validate this file against a server which does not know 'hobby' property, I want the editor to mark error on that property.
I have plans to add much more functionality to this dsl/toolkit.
Any hints which technology is more suitable ?
thanks
I know this can be done by xtext or jetbrains mps etc. But, I want to understand which technology lends for the following requirements.
I think Xtext is good for your requirements under the condition that you have (or can create) an XML schema for your XML domain models.
the models are fed to the system at run time (new, updates, deletes etc). so, I cannot have static set of grammars. How can I structure it so that the model/property assist is resolved at run time or at least the grammar is generated (may be a part of it)
If I understand you correctly, you don't really need specific grammar rules for each XML data model but only cross references to the data model.
EMF has support for generating EMF Java classes from XSD files and Xtext can reference XML files conforming to the XSD schema if you add them to the Xtext index using your custom indexer (Xtext interface IDefaultResourceDescriptionStrategy).
So you can create a normal Xtext project with grammar etc. for your DSL and use cross references that refer to your XML domain model.
when I am working with one set of 'grammars' , if I point my target server to a different version (which may have different set of models) , I want the editor validate my existing files and flag errors.
I get the data files in xml, text or via server lookups.
EMF uses URIs to identify resources so if you generate an Ecore model like I described, it should be possible to import the XML domain models using http:// or file:// (or whatever, it's extensible) URIs, or something that you internally resolve to URIs.
It is very important for me to transform the models into some other format or interpret them in java/groovy.
Here you have the choice between making an interpreter, an Xbase inferrer or a generator (each of which can be implemented well using Xtend), depending on your requirements.
(Disclaimer: I am an employee at itemis, which is one of the main contributors to Xtext)

Basic Openxava examples

Looked at some applications built using Openxava and it seems like a very useful peice of kit. However I am trying to find a very basic worked example ( helloworld type ) but can't find any. I have looked at the Openxava bundled examples but even these have too much 'magic' going on in them where the only thing you code is a single Entity class and next step is viewing a working Web Application. How is the UI created??
I'm looking a simple example like where I have a simple business class with a single method that returns a "helloWorld" string, how do I display that as the text on a button on a web page?
Writing an entity class to get a working web application is the simplest thing you can do with OpenXava. Most Java Framework are low level, focused in infrastructure, where you have to do all the work to get the application. OpenXava is high level where you have all the hard stuff done, you only have to write your data structure and your business logic.
But you can use plain JSP. If you want that your OpenXava application says "Hello", create a hello.jsp in the web folder and put inside it "Hello". 4 characters of code, less than Spring Boot.

How to create custom extension point in ReSharper plugin

We are working on plugin for ReSharper and we want to make our plugin extensible. Seems, we should use ShellComponent attribute to do it but we can not find any examples. Could anybody enplane how to define custom extension point and how to manage extension. Example of code of extension point and extension implementation would be very helpful.
Thanks.
If you're looking to write a plugin that can extend ReSharper, you need to tell ReSharper about the classes in your plugin, by marking them with the [ShellComponent] or [SoutionComponent] attributes. These attributes have different lifetimes - a shell component lasts the lifetime of ReSharper itself, and a solution component is created when a solution is opened and disposed when the solution is closed.
To make ReSharper do something useful with your components, they typically have to implement an interface, such as ICodeCompletionItemsProvider, and sometimes have to use a different attribute, such as [CodeCleanupModule] (which itself derives from ShellComponentAttribute). There are many extension points in ReSharper, and the one that's appropriate for you depends on what you're trying to do - refactoring, unit test provider, code cleanup, code completion items, etc. The devguide provides a good introduction to the more common extension points.
But if you want to make your own plugin extensible, then your component needs to work with a kind of provider pattern, by deferring work to multiple provider instances. For example, code cleanup works by deferring to multiple code cleanup modules, each responsible for cleaning up a different aspect of your code (whitespace, ordering, etc). To do this, your component should take in a collection of providers in the constructor. ReSharper's component model will automatically create a collection of these types and pass them to. More specifically, you should have a constructor that takes an IEnumerable<T> or IViewable<T>, where T is the interface of the provider you're going to define and call. The IEnumerable<T> will give you a simple collection of providers, but IViewable<T> represents an observable collection, and allows you to subscribe to notifications of new providers being made available from the component model.

Adding methods to Class when using Model-first in EntityFramework 5

In EF4, I would generate my model from the DB. Then I would extend the classes using partials. This allowed me to regenerate from the DB without losing my code.
In EF5, when generating from the model, it creates a .cs file for every item in DB. I actually like this a lot more except, I am not sure what the best way to extend the objects is. If I write my changes right in the MyObj.cs file, I will lose them if I have to re-generate the model. I guess I chould create file MyObjPartial.cs and make the class partial there... thought?
~S
You should follow the same pattern as before, by using a partial class. This is basically the same with all auto-generated file types and EF is not any different. You want to make sure you don't lose the changes when you regenerate the file.
Partial classes are also great in this example as a separation concept, that way you have the stuff that's important to your application separate to the stuff that's important for the running of Entity Framework

How to add "Using " statement at runtime using IWizard

at compile time we have
using MyNamespace;
This works till now but recently the requirement got change and it needs to handle at run time based on the application type selected by the user.
So, How can I add the "Using" namespace statement using c# code in the IWizard?
I know how to add the reference at run time ass under
var appProject = project.Object as VSProject;
appProject.References.Add(Mydll);
What I want is that at runtime
using System.IO;
using MyNamespace-> should come at runtime based on the application selected
Thanks
I just hit a similar issue and while it is not exactly changing the namespace at run time it does all you to get objects etc from a different namespace at run time. If you want to be changing namespaces chances are you have classes with the same names and interfaces but different implementations otherwise your code would need to be changed. What you need to do if make a new lib and namespace that just contains the interfaces for all the classes you want to use. You then make the classes in the different namespaces inherit these interfaces so you can code your class to just use the interface not the particular implementation. Then to select the implementation to use at run time you use "Dependancy Injection" to choose the correct implementation to insert via config file or let some other part of your application configure the injection. Dependancy Injection can be a little hard to get started with but once you get your head around it, it will make your life a lot easier. Ninject is a nice easy dependancy injection framework to start with.

Resources