How to Map ComplexType in EntityFramework.

307 views
Skip to first unread message

ankit1...@gmail.com

unread,
Feb 5, 2015, 8:00:05 AM2/5/15
to automapp...@googlegroups.com
I do have a parent Entity,
class Parent
{
  public string Name {get; set;}
  public ComplexTypeChild ComplexTypeChild {get; set;} 
}
class ComplexTypeChild
{
   public string address{get; set;}
}
 
How can I add Automapper for this. I am using Entity Framework.

Patrick Steele

unread,
Feb 5, 2015, 8:13:51 AM2/5/15
to automapp...@googlegroups.com
Do you want to map the "Parent" class to something?  What does the destination class look like?

--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ankit Gupta

unread,
Feb 5, 2015, 8:36:22 AM2/5/15
to automapp...@googlegroups.com
Hi Patrick,

Actually I am trying to Map to Parent to it's DTO like this:
Mapper.CreateMap<Parent, ParentDTO>() but getting the below exception:

Unable to create a map expression from ComplexTypeChild to ComplexTypeChildDTO

Here ComplexTypeChild is not a database table but working as ComplexType of Entity Framework.

Ankit Gupta

unread,
Feb 5, 2015, 8:39:04 AM2/5/15
to automapp...@googlegroups.com
tried doing the below...but it didn't worked:
 Mapper.CreateMap<ComplexTypeChild, ComplexTypeChildDTO>()

Jimmy Bogard

unread,
Feb 5, 2015, 8:47:36 AM2/5/15
to automapp...@googlegroups.com
You're going to need to post your full source/destination types. And the full exception, too.

On Thu Feb 05 2015 at 7:39:05 AM CST Ankit Gupta <ankit1...@gmail.com> wrote:
tried doing the below...but it didn't worked:
 Mapper.CreateMap<ComplexTypeChild, ComplexTypeChildDTO>()

--

Ankit Gupta

unread,
Feb 5, 2015, 9:43:18 AM2/5/15
to automapp...@googlegroups.com
The below error I am getting.
 
Only primitive types, enumeration types and entity types are supported.

Jimmy Bogard

unread,
Feb 5, 2015, 9:48:18 AM2/5/15
to automapp...@googlegroups.com
Here's what I need: The source AND destination types, the mapping configuration, and the code you're using to get the exception.

Please.

On Thu Feb 05 2015 at 8:43:20 AM CST Ankit Gupta <ankit1...@gmail.com> wrote:
The below error I am getting.
 
Only primitive types, enumeration types and entity types are supported.

--

Ankit Gupta

unread,
Feb 6, 2015, 1:30:27 AM2/6/15
to automapp...@googlegroups.com
Mapper.CreateMap<Source, Destination>()

as DestinationVersion and SourceVersion  are of ComplexType.

I am getting error for get operation of web api
context.Sources.Project().To<Destination>();
Destination.cs
DestinationVersion.cs
Source.cs
SourceVersion.cs

Ankit Gupta

unread,
Feb 8, 2015, 9:13:55 PM2/8/15
to automapp...@googlegroups.com
hi,
 
can anybody respond on this please.

Jimmy Bogard

unread,
Feb 9, 2015, 9:10:54 AM2/9/15
to automapp...@googlegroups.com
I'm looking at your Source/Destination types, and they look *nothing* alike. Are you sure you're sending me the right types? Source has three properties, none of which have the same name on Destination. Destination has a dozen or so properties.

It looks like you're trying to map a potato to a banana, and are surprised when it doesn't work.

When you run Mapper.AssertConfigurationIsValid(), what do you see?

Ankit Gupta

unread,
Feb 9, 2015, 10:24:54 AM2/9/15
to automapp...@googlegroups.com
re-uploaded the corrected files..please have a glance once.
Destination.cs
DestinationVersion.cs
Source.cs
SourceVersion.cs

Ankit Gupta

unread,
Feb 9, 2015, 10:26:40 AM2/9/15
to automapp...@googlegroups.com
ran Mapper.AssertConfigurationIsValid(). it didn't got me any exception/error.
Reply all
Reply to author
Forward
0 new messages