0
votes

I have started working on an application which is structured as follows:

UI - ASP.Net MVC web application Service Layer - WCF Entities - a simple class library (exposed by WCF layer) Data Layer - for database interactions.

Till now, I was defining my models in Models folder of my web application, but now as we have decided to expose them by WCF service (as this application will be consumed by other applications as well), I need some help here.

I tried putting all my model definitions in Entity layer which is exposed by WCF service decorating them with data annotations as well as DataContract attributes. Now, I am able to reference these entities to bind them with my views. But, data annotation validations are not working for me.

Can anybody please help me for a workaround for this ? I have been searching through web for solution but almost all tell me to put a reference of entity layer in web application which will be tight coupling that we do not want. and the other option is to redefine all entities with data annotations in models folder of my web application,which will be duplicate kind of coding.

Is there any better approach for this? Any help appreciated.

Update:

To consume WCF entities, I have put a service reference in my web application. Now, just to check I modified that Reference.cs file by decorating my data Member explicitly with [Required] attribute and it is working fine. but, I understand these changes will go away whenever service code is generated.

Is there any way I can bring that Data annotation attribute here? Kindly help.

1

1 Answers

0
votes

As for me It's bad idea, DTO for transfer, Model for MVC.

Look like similar problem