I'am currently following a tutorial of ASP.NET MVC in which instructor use auto mapper version 4.x and now i have only option of version 5.
When I create a mapping profile in which i get an error Mapper does not contain a definition for CreateMap:
I've attached all pictures of :
My Mapping Profile.
My Global.asax.cs.
/api/customer is working fine.
/api/movies is not working.
Is there something wrong i did or missed something?
Here's the link of my images
CreateMap is an instance method of the base class Profile
Just call
public MappingProfile()
{
CreateMap<A,B>() //...
}
Related
It's the first time I create a back end for my Xamarin.Forms application. I follow instructions on Azure Portal -> Quick-Start, create a data connection, choose c# in step 2 and download the project.
Build it and now I want to add a new table. So :
I add the class in DataObjects folder.
I add the line in the Context file : public DbSet<Coffee> Coffees{ get; set; }
And when I try to add the Azure Mobile Apps table controller, an error message tell me :
Value cannot be null. Parameter name : path1.
What can I do to fix that ?
Sorry for my bad English.
Have a nice day!
I have the same problem, and the problem is also mentioned on the Visual Studio Development community: https://developercommunity.visualstudio.com/content/problem/563354/adding-a-new-azure-mobile-apps-table-controller-or.html
Meanwhile you can work around the problem by creating the controller in code. I've tested the following steps for a Azure Mobile Apps Table Controller for a Xamarin Forms app:
Add a new class to the Controllers folder, i.e. {YourDataObject}Controller.cs
Take an existing and working controller and copy the code into the new controller file.
Replace {OldMobileAppName}Service and {OldMobileAppName}Context with {NewMobileAppName}Service and {NewMobileAppName}Context
Replace {OldDataObjectName} with {NewDataObjectName}
Finally publish your solution.
Configuring a Table Controller requires three steps:
Create a Data Transfer Object (DTO) class.
Configure a table reference in the Mobile DbContext class.
Create a table controller.
A Data Transfer Object (DTO) is a plain C# object that inherits from EntityData. An example from the documentation:
public class TodoItem : EntityData
{
public string Text { get; set; }
public bool Complete {get; set;}
}
Please reference this documentation for more information.
I have an application using Glide 3.8.0 and I've just migrated it to 4.8.0. After migrating all the code to use the new Glide's API, I've found that my app launches this error when trying to load an image from the network:
java.lang.AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"
at com.bumptech.glide.Glide.initializeGlide(Glide.java:268)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:221)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:182)
at com.bumptech.glide.Glide.get(Glide.java:166)
at com.bumptech.glide.Glide.getRetriever(Glide.java:680)
at com.bumptech.glide.Glide.with(Glide.java:732)
at com.fewlaps.android.quitnow.usecase.main.MainActivity.updateAvatar(MainActivity.java:356)
etc...
I've done the setup explained in the official documentation. As it requests, I wrote a class that extends AppGlideModule, it's annotated by #GlideModule, and it's empty. Empty? The official documentation says:
You’re not required to implement any of the methods in AppGlideModule for the API to be generated. You can leave the class blank as long as it extends AppGlideModule and is annotated with #GlideModule.
According to the Error's message, my issue is related with registerComponents() for sure, but I also tried to implement it with a blank implementation, and the issue remains.
As explained in AppGlideModule's JavaDoc (and as far as I know, only there...), if you are done with the migration from 3.x.x to 4.x.x, you have to implement isManifestParsingEnabled() returning false.
So, you'll end with a CustomAppGlideModule like this one:
#GlideModule
public class QNGlideModule extends AppGlideModule {
#Override
public boolean isManifestParsingEnabled() {
return false;
}
}
I want to create a Link to a resource within a Spring Data REST Repository. I know that we can use ControllerLinkBuilder.linkTo method to create links to MVC controllers. As far is I understand Spring Data REST creates MVC controllers out of our Repository interfaces. But if I use
Instance createdInstance = instanceRepository.save(instance);
Link link = linkTo(InstanceRepository.class).slash(createdInstance.getId()).withSelfRel();
to create the link, I just get http://localhost:8080/2 (without the Repository path). Nothing changes if I specify the path explicitly with the #RepositoryRestResource at the Repository.
Of course I could just create the link explicitly, but I don't want to repeat myself.
public interface InstanceRepository extends CrudRepository<Instance, Long> {
}
Any advice on what I could do to resolve this issue without having to violate DRY principles?
Searching through the Spring Data REST source code I found the class RepositoryEntityLinks, which is used within the framework. It has a pretty nasty constructor, but (at least in my project) I am able to #Autowire the class.
In short the following code does the trick. Nevertheless I would be pleased to hear another persons more educated opinion on this!
Link link = entityLinks.linkToSingleResource(InstanceRepository.class, 1L);
If anyone is confused on how to piece it all together, you need to inject RepsitoryEntityLinks into your controller like so. Note no AutoWired is needed since spring will automatically inject the values if theres just the 1 constructor.
entityLinks.linkToCollectionResource(TodoRepository.class) is saying to spring - "give me the link to the TodoRepositories collection endpoint which would be something like localhost:8080/api/todos"
#RestController
#RequestMapping(value="/api")
public class PriorityController {
private RepositoryEntityLinks entityLinks;
public PriorityController(RepositoryEntityLinks entityLinks) {
this.entityLinks = entityLinks;
}
#GetMapping(value = "/priorities", produces = MediaTypes.HAL_JSON_VALUE)
public ResponseEntity<Resources<Priority>> getPriorities() {
Link link = entityLinks.linkToCollectionResource(TodoRepository.class);
resources.add(link);
return ResponseEntity.ok(resources);
}
}
In my application I was using the old SQLite-plugin.
Since MVVMCross 3.0.14 this version is deprecated and the Community.Sqlite plugin is advised.
The Community plugin was added via Nuget.
When trying to use the plugin without a bootstrapper, at runtime I get the error:
Failed to resolve parameter for parameter connectionFactory of type ISQLiteConnectionFactory when creating...
When trying to use the plugin with a bootstrapper, also at runtime, I get the error:
plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite
How should this plugin be used?
-Edit-
This is my bootstrapper code:
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
public class SqlitePluginBootstrap : MvxPluginBootstrapAction<PluginLoader>
{
}
Okay, Nuget added a reference to the portable library. I added a reference to the Sqlite.Touch library and then altered my bootstrapper:
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}
This solved the "plugin not registered"-error for me.
Confirmed - I came across the same issue.
Nuget downloads the right things, but only adds the one reference, as Jacco points out.
It doesn't add the reference to Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch.dll, and it doesn't put the bootstrap in for you automatically.
I have one extra using statement in my bootstrap for MvxLoaderPluginBootstrapAction. Here's the complete code:
using Cirrious.CrossCore.Plugins;
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}
I am in the begining of making a simple website using ASP.NET MVC4 CodeFirst Approach. The web site is built around users who are able to register, make posts etc. The existing UserProfile class was modified for the accommodation other fields (ex: FirstName, LastName etc).
When I ran the website I got a similar error:
Invalid column name 'FirstName'.
Invalid column name 'LastName'.
Invalid column name 'Phone'.
I red that this is because the Database is not updated as the model is updated. So I set the following on the Application_Start() in Global.asax with the intention of droppnng the database always (at least until I get the hang of it).
protected void Application_Start()
{
Database.SetInitializer(new DropCreateDatabaseAlways<UsersContext>());
//Other default generated stuff below...
}
I also tryed the DropCreateDatabaseIfModelChanges, but both methods didn't drop the database.
Isn't this possible? Why is it? Am I doing some thing wrong?
I believe it would be possible to store the info in a different table and link it to this, but I prefer to keep it in one table.
Also is it a bad idea to add UserProfiles to the websites context (lets say: DatabaseContext (which has other entities like Posts, Comments etc) and change the AccountsController to use DatabaseContext instead of UsersContext?
Thanks in advance.
Have you run Enable-Migrations in the Package Manager Console? You should see a migration folder in your project, with a configuration.cs file, ensure you have enabled automatic migrations.
public Configuration(){
AutomaticMigrationsEnabled = true;
//if you drop columns - consider this carefully...
AutomaticMigrationDataLossAllowed = true;
}