C# - Is It Possible To Map Multiple DTO Objects To A Single ViewModel Using Automapper
Jan 24, 2010
I was wondering if it is possible to map multiple DTO objects to a single ViewModel object using Automapper?
Essentially, I have multiple DTO objects and would like to display information from each on a single screen in ASP.NET MVC 2.0. To do so I would like to flatten the DTO objects (or parts of them...) into the Viewmodel and pass said viewmodel to the view. If I had one DTO this would be easy, but I've never seen it being done with multiple. Obviously there are a number of roundabout ways to do this (outside of automapper), but this is the approach that I would like to take if possible.
public class ComponentType { public int ComponentTypeID { get; set; } public string Component_Type { get; set; } public string ComponentDesc { get; set; } } [code]...
In my application, I need to get data from three tables and display them in 1 view. I have created a .dbml and created a ViewModel in my Models folder to deal with this. Here is my ViewModel:
[Code]....
My web application uses the Default ASP.NET Membership. So User [ u ] is of type aspnet_Users from the default Membership. This ViewModel allows all the CRUD opertation to be carried out. However on the Create and Update operations, I would LOVE some Model Validations, My question is:
1) Would the User [ u ] default validation kick into place in my ViewModel ? Cause I know by default ASP.NET Membership, has Model Validation.
2) For table SUserDetails (which I have created myself, not part of default) how do I add ViewModel validation to it for when someone does an Update or Create?
I have a table in my database with a one to many relationship to another table, which has a relationship to a third table:
[Code].....
This seems to work fine. My question to you good folks: Is there a correct way to do this? I tried following the making a custom model binder per the blog link I posted above but it didn't work (there was an issue with reflection, the code expected certain properties to exist) and I needed to get something going ASAP. PS - I tried to cleanup the code to hide specific information, so beware I may have hosed something up.
I am currently designing a new .NET application and would like to keep it UI independant.
Whilst I initally would like to use WPF, I would like to have the option of swapping the UI to ASP or WinForms if necessary.
In a layered design:
View - Interface Controller (ViewModel) - Model - Persistance
is it possible to design the Interface Controller so that it will work with different view technologies, or will I need to replace the interface controller at the same time as the View?
I have a stored procedure that returns 3 tables within the single recordset it returns. If I set a SqlDataSource to get data from this procedure, it works, but it only returns the first table. I want to have a GridView display the data from the 2nd or 3rd table using a SqlDataSource, but I can't figure out how to specify a particular table.
While there are some posts discussing this out there, I can't get a definitive answer about whether or not this is even possible (?). In a worst-case scenario, I can create another SP that only returns the 3rd table - but that creates a little maintenance headache that I would prefer to avoid.
1.) What is the name of the OS process in which App Domain resides.
2.)if suppose There are Three Windows application hosted on a same envoirment and two instance is working for each application at a Time, means now total instance are six .what will happen among the below written cases :
a.) There will be six different app domain in a single OS process
b.) There will three app domain(one for each application) in a single OS process and some Parallel thread will be executed in each app domain for another instance.
c.) There will be Three OS process corresponding to each application.
3.) If eveything will remain same except there are three web application in place of windows in point 2, will there be any change in functioning.
I have a question in gridview, I want to combine my two or more records into a single cell with two rowsfor Example i have a ID, Name, Year Start, and Year End for Column name in database and i want call it into my gridview that the Year Start and Year End will combine to Year like:
I have a view that is based on a view model. This model has a single property called Entity, of type ServiceProvider, which is a Linq2SQL object. This object has relationships to 2 other objects Address and ServiceProviderGroup. In a HTML view I have textboxes that allow the properties of the Entity property to be changed and also the properties of the Address object related to it.
E.g: ViewModel.Entity.Code, ViewModel.Entity.Name, ViewModel.Entity.Address.City, etc, etc.
There is also a selectlist that will allow the Entity.GroupId (int) property to be changed. This defines a relationship to the ServiceProviderGroup class which is also accessible via a Group propery. (standard linq2sql back references)
The Edit[Post] method accepts an instance of this view model and all properties (on the Entity, Entity.Address properties) are set as expected. I then lookup the original object in the database and I also bring back the original address and group data.
E.G: entity => entity.Code == viewModel.Code && entity.Address.Id == viewModel.Address.Id && entity.Group.Id == viewModel.Entity.GroupId (I'm not looking at the code, but it's something similar to this)
Either way the original Entity, Entity.Address, etc, come back from the database. I then apply the changes from the view model to the original object using UpdateModel and everything is updated as expected. But, if I try to change Entity.GroupId, i.e. change the relationship on the entity to another ServiceGroupProvider object, I get an exception in the generated code of the ServiceProvider object.
This happens in the GroupId property of the ServiceProvider class (viewModel.Entity). When it reaches the line if(!this.HasLoadedOrAssignedValue) it enters the "if" statement and throws an exception. When the data is first read from the database it skips this part. But, when UpdateModel attempts to apply the new Entity.GroupId value it throws the exception.
I have a form which I use to create an issue. WHen you post the form, the form elements are that of a custom DTO. The DTO is then used on my POST method to create the new entity. That all works fine.
However, I want to add the functionality to add multiple issues at the same time from the same view. In effect, the user would click something like 'Report Additional Problem', and an extra set of form fields would appear (I will like use jquery for this, which I don't have an issue with). However, even with just leaving one set of form fields, the user should still be able to create just one issue. But if I habve my post method take a list or array of my DTO, it doesn't work.
Here is the post method before editing:
[Code]....
What I want to do is for this to take an array or list of NewIssueDto. I would then loop through each one in the list and create a new issue from it.
I am looking for an accepted pattern for using MVC 2 and EF. Especially I am interested on how to implement updates. Where should the ObjectContext be created, where should the queries be, how to pass a model object from the controller and have it persisted with minimum robust code. I also want to be able to use transactions when updating multiple objects.
I used Linq in an asp.net application (code behind model). With EF I was hearing it was much more n-tier friendly, but I don't find it any different, rather than people talking about POCO which to me, all it means is satisfying the desire of those that want to have control of every piece of code being created.
<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>
This may be a little more up the alley of our mvc fellows, but regardless.
First, I have the following model:
Csharp Code:
[code]....
Notes: RenderPartials is a custom extension method and that part works, as do the actual views. The correct data is displayed. Just not in the expected order. In fact, it mirrors the database.
Can it handle mapping using private members like NHibernate can? The documentation is very slim, but it seems like one of the objects or methods provided with the tool could do something like this.
since asp.net contains multiple threads that are executing at the same time.so if 2 threads access an object (simple or complex) that i got from the the asp.net httpcontext Cache.can't this lead to state problems on that object if these 2 theads tried to modify/read it at the same time?so what kind of precautions should i implement?for example i am thinking maybe locking the object while working with it? (wont this cause performance problems?)or maybe when i retrieve some object from the cache i should create a copy from it? or maybe i dont need to worry about this issue at all?
I'm trying to figure out the best approach to architecting this project. Basically, it's a "band" profile site. I'm using ASP.NET 4, EF, and Automapper (structuremap too, but that's not important). I'm running into performance issues I have a EntityFramework repository class that interacts directly onto the EF objects using LINQ:
[Pluggable("Repository")] public class EntityDataRepository : IRepository static EntityDataRepository() // other mappings removed // Data. objects are EF objects, mapping to my DTO classes [code]...
Is it possible with automapper in C# to map the properties of an object to an array/dictionary? I have tried the following:
Mapper.CreateMap<FFCLeads.Models.FFCLead, Dictionary<string, SqlParameter>>() .ForMember(d => d["LeadID"], o => o.MapFrom(s => new SqlParameter("LeadID", s.LeadID))) .ForMember(d => d["LastName"], o => o.MapFrom(s => new SqlParameter("LastName", s.LastName)));
However, it does not work (object ref not set to an instance). Basically, I'm trying to make the values of this object to an array of SqlParameter objects. Possible? If so, what is the correct way to do this?
In a typical business application, a session is started and persisted across several pages. It is commited only when the transaction is complete. A good example of this is a tax preparation application. Once the session is started, it is persisted through session, cookies, or both. Nothing is written to file, or database, until the entire profile is complete and the refund/return is calculated. In such an ennvironment, is makes a great deal of sense to work with the structure imposed by domain driven design, and using a single repository to simple commit the session. However, there are times when this doesn't translate correctly, even when domain driven design is used.
An example of this is my forum project. While the entities themselves are good targets for domain driven design, I am not sure about the repositories. The basic structure is that a Category has many Forums, a Forum has many Threads, and a Thread has many posts. There are other things in there, but that's enough to describe what I want to get across. If a user has navigated to /Thread/Edit/42, and they have rights to edit it, all I am concerned about is fetching that record and displaying it. On postback, all I want is to be able to save it..................
I have a web project which includes two button in a view.when i click a button some textboxes along with that second button have to be visible.After entering data in textboxes,when i am trying to click the second button, its not working.What should i do to make it work?