How To Sort Automapper

Jul 24, 2010

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.

View 5 Replies


Similar Messages:

.net - Whats Automapper For

Jan 19, 2010

What's Automapper for? How will it help me with my domain and controller layer (asp.net mvc)

View 3 Replies

Forms Data Controls :: How To Change Sort Column Header Text And Retain The Sort Link

Jun 3, 2010

I have a simple dynamic gridview with following code -

GV = new GridView();

View 3 Replies

Can Use Automapper And Private Members

Mar 23, 2011

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.

Mapper
.With<FooDTO>()
.Map(x => x.Value)
.To<Foo>("_value");
// To<T>(string member) or To<T>(Func<T, bool> func)
Mapper.CreateMap<Foo, FooDTO>();

I know my example methods don't exist as-is, but maybe I've overlooked something else already built in.

View 1 Replies

C# - MVC, EF Layer, And Automapper Setup For A Project

Jan 17, 2011

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]...

View 1 Replies

C# - Using AutoMapper To Map Object Fields To Array?

Feb 16, 2011

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?

View 1 Replies

Web Forms :: DataView.Sort Vs List.sort?

Mar 7, 2010

Actually i want to ask which is the best for sorting in Asp.Net is it DataView.Sort Method or List<Object>.Sort() method.

View 1 Replies

Web Forms :: Sort Datatable Without DefaultView.Sort?

Apr 20, 2010

I'm looking for a way to sort the rows of a datatable without setting the DefaultView.Sort to a specific column. I have a datatable in session that users can add records to. I want them to be able to sort the data by clicking on a button. But new records added after that need to show up at the bottom of the list until the sort button is clicked again.

View 2 Replies

What Is The Alternative, Using POCO Classes In Combination With For Example AutoMapper

Sep 30, 2010

Currently im using EF and using its datacontext directly in all of my actions, but since i started reading about loose coupling and testability im thinking that thats not the best way to go. Im trying to understand all the pro's and con's before i start refactor all my current code.

Problem 1:

Considering that every entity needs its own repository, and thus has to setup its own connection to a datasource (lets assume a database using EF), wouldnt that give alot of overhead if i need data from 5 different entities on a single page?

Problem 2:

What im seeing aswell in all the examples which i found online is that most people (even people like shanselman) implement the repository pattern using the entity classes which are generated by either LINQ or EF, doesn't this defeat the purpose of repository pattern with regards to loose coupling? On the other hand, what is the alternative, using POCO classes in combination with for example AutoMapper? (this scares me a little) Im hoping that a few people can shed some light on this, because im a bit confused at the moment if the repository pattern is the right choice for a website.

View 6 Replies

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.

View 1 Replies

Trying To Use AutoMapper For Model With Child Collections, Getting Null Error In .Net MVC 3

Feb 26, 2011

I'm completely new to AutoMapper, and I have a View that looks like this:

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Consultant</legend> [code]...

This is pretty much the same error I got when trying to use the entity object directly as model, rather than having AutoMapper create a ViewModel. So what am I doing wrong? This is driving me crazy...

UPDATE 3:Well, neverending story... I found some info on using UseDestinationValue on the CreateMap method in AutoMapper. So I tried that, and well, that actually got me a bit further. But...now I get a new exception on SaveChanges() (in the EF model). The exception now is: "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable." This appears to be an exception that also occurs when trying to delete child objects in a one-to-many relationship if you don't have cascade delete set, but that's not what I'm trying to do here...

Here's the updated CreateMap methods:Mapper.CreateMap<ConsultantViewModel, Consultant>().ForMember("Id", opts => opts.Ignore()).ForMember(
x => x.Programs, opts => opts.UseDestinationValue());
Mapper.CreateMap<Consultant, ConsultantViewModel>();

View 1 Replies

Automapper, Auto Assign Guid To UserId Of UserDTO?

Dec 1, 2010

I want to assign Guid to UserId of my UserDTO if UserId is Null. Is it possible to do this in the CreateMap or creating any formatter?. I am using automapper as an attribute on my Actions in controller.

protected override void Configure()
{
Mapper.CreateMap<User, UserDTO>()
.ForMember(d => d.FullName, o => o.MapFrom(s => s.FirstName + " " + s.LastName));
}

View 1 Replies

C# - Automapper Running Extremely Slow On Mapping 1400 Records?

Nov 9, 2010

I am using AUtomapper which I am very impressed with however, I have a complex object with many nested collections. I'm using Telerik OpenAccess and it returns the 1400 records fast but when I pass it to Automapper and it slows to a ridiculous crawl. Here is my code for reference:

List<DAL.Event> query = httpContext.Events.Where(e => e.Inactive != true && e.Event_Locations != null).ToList();
Mapper.CreateMap<DAL.Event, EventDTO>();
Mapper.CreateMap<DAL.Event_Association, EventAssociationDTO>(); [code]....

View 2 Replies

MVC & AutoMapper (Populate View Model From Parent & Child Domain Objects)

Feb 7, 2011

I have following doimain objects:

public class ComponentType
{
public int ComponentTypeID { get; set; }
public string Component_Type { get; set; }
public string ComponentDesc { get; set; }
}
[code]...

View 2 Replies

Forms Data Controls :: Gridview Sort Expression - How To Reset A Gridview Or Prevent It From Doing A Sort

Sep 23, 2010

Just spent about 8 hours googling and looking through this forum for a solution on how to make sure that I can dynamically sort. Here is the situation.

I have 1 Gridview that displays 10 different scenarios based on what button is clicked.

I am also returning only top 10 records. I am doing all of the data binding pragmatically. So I have BoundFields, HyperLinkFields etc.

I also want to sort some records. When I change DataSource SQL statement the gridview somehow remembers what the last sort value was and it errors out saying that value "x" cannot be sorted because it does not exists.

I tried this:

Tried setting gridview1.sqldatasourceid = null; gridview1.allowsorting = false; gridview1.databind();

Here I get an error that says that the data source does not support sorting? Doesnt it say gridview1.allowsorting = false;

I also tried gridview1.sort("", SortDirection.Ascending); This does nothin... except query my database one more time because i have a onSorting event that looks like this:

[Code]....

Here is an example of just one of those SLQ statements inside GetSQLQuery:

[Code]....

View 1 Replies

Forms Data Controls :: How To Sort Data In GirdView Via Sort Icons Clicks

Feb 28, 2010

i read Matt Berseth article also i downloaded this source. But i can not do sorting event. Everything is ok but sorting is not working.

[Code]....

View 3 Replies

ADO.NET :: How To Sort On A Column

Aug 2, 2010

var regionNameList = regionDataContext.regionDataViews.Select(region => new { region.RegionName, region.RegionNumber }).Distinct().ToList();

regionnamelist needs to be "order by regionname".

View 1 Replies

MVC :: How To Sort Dropdownlist

Mar 21, 2011

This code am using in controller

[Code]....

View 1 Replies

Sort An Unbound Datatable?

Jul 2, 2010

Is it possible that once I have created a datatable programatically, I can then sort that datatable before binding it to a asp:repeater? I have a number of records that I have to get from a com object that has not been eliminated. The com object populates an array, then I loop through the array to pull data from my datatbase, adding the db data to the datatable. Then I bind the datatable to a repeater.

1) the array is multidimensional
2) The COM object doesn't sort the data by company ID (which is what I need to do)

View 3 Replies

Sort Array Along With Its Corresponding Index?

Oct 28, 2010

I have a one-d Array named zz containing {5,3,8,1,9,6}. Current order of indices of the elements is : 0,1,2,3,4,5.

Now I want to sort the array z in ascending order in such a way that its corresponding indices also sort according to its respective elements.

Ex: Elts in Ascending order : 1,3,5,6,8,9

and Respective indices will be : 3,1,0,5,2,4.

Another Ex: What "Additions" should i make to the following code, if the Array Element repeats ?? Epected Oreder of Indices : 1,0,4,3,2

[code]....

View 3 Replies

Sort DataAdapter Alphabetically - VB.Net

Nov 30, 2010

This should be a fairly simple one. I am creating a dataset which will contain a description field which I would like to sort by. The reason I want to sort the dataadapter and not in my SQL is that I am already ordering by the results that have a particular value. My SQL looks like this:

SELECT pif_desc, pif_fund, psf_end, (CASE WHEN SUM(pmi_units) IS Null THEN 0 ELSE SUM(pmi_units) END) As fundunits FROM tbl_mem INNER JOIN tbl_sfunds ON pm_scheme = psf_scheme INNER JOIN tbl_invfun ON tbl_fund = tbl_fund LEFT JOIN pe_minv ON pmi_fund = pif_fund AND pm_member = pmi_member WHERE pm_member = @pm_member GROUP BY pif_desc, pif_fund, psf_end ORDER BY fundunits DESC

My VB looks like this:

Dim cmd As New SqlCommand("getMembersFundsDCGENST", conn)
cmd.CommandType = CommandType.StoredProcedure
Dim p_pm_member As New SqlParameter("@pm_member", SqlDbType.Int)
p_pm_member.Value = pm_member
cmd.Parameters.Add(p_pm_member)
Dim p_period_closing_date As New SqlParameter("@closingdate", SqlDbType.DateTime)
p_period_closing_date.Value = period_closing_date
cmd.Parameters.Add(p_closing_date)
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)

I want to sort the datarows is ds.tables(0) by pif_desc but still have the rows with fundunits > 0 listed first.

View 2 Replies

C# - How To Sort A Dictionary Object In C# 2.0

Jul 14, 2010

How do you sort a dictionary object in C# 2.0 for asp.net or is their an alternative to Dictionay for sorting this is to sort a countries list alphabetically

View 3 Replies

ADO.NET :: Sort By The First N Characters Of A String?

Feb 9, 2011

I need to be able to sort by a product title and then by a products price, which is simple but I only want the title sorted on the first 3 or 4 characters. My client wants to add the brand name to the beginning of the product title and have them automatically sorted. I can a new field in the database called brand and sort by that, but wanted to know if this is possible. I've posted what I though might work but it doesn't

[Code]....

I guess this is probably possible with a lambda expression, but I've no experience with Lambda expressions at all.

View 1 Replies

Web Forms :: Can't Get Dropdownlist To Sort

Mar 12, 2010

I am using Visual Studio 2008 and SQL Server 2008, I have a drop down list on my page that gets its data from SQL. My SQL tabel only has 2 columns, "HeaderId" and "Header". So on my drow down list I have the value field set as the "HeaderId" and the text field set as the "Header". What I need now is that when it is bound to the list to be in order of the "HeaderId". I tried doing and ORDER BY but it did not work. What can I do, is there a better way of doing this? Here is my code to populate the list:

[Code]....

View 5 Replies

IComparer For ArrayList.sort?

Feb 28, 2010

How to compare array in arraylist by name.I try many thing but no one works.public class myReverserClass : IComparer { int IComparer.Compare( Object x, Object y ) { ... }

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved