开发者

21 entities with the same structure. What I'm supposed to do when it's time to make a CRUD for these entities

I Have 21 entities with the same structure. Same Attribute too.

Every entity contains these Attributes :

AreaType

ID

IsActive

LangID

TXT

ModuleType

ID

IsActive

LangID

TXT ...

What I Need to perform a generic Crud. I already know that I need to create a generic repository. My problem is to perform a kind of generic ViewModel.

How can I create a generic View for the Create Form.

I Dont know what I need to pass in the Inherits of the view t开发者_JAVA百科o be Generic.

 ... Inherits="System.Web.Mvc.ViewPage<...Dont know>"

Any Idea ?


A common approach this problem is to use ViewModels. This is where you create specific classes to be used as the models in your strongly typed views. These classes would not be the ones created by EF. The ViewModel classes can have a common base that encapulate your common fields. In your data access layer you would need to move data between your ViewModel classes and your EF classes. Things like AutoMapper (from CodePlex) work really well to reduce, if not eliminate, all of the the tedious "left-hand right-hand" coding.


Not too familiar with MVC, but (assuming it fits in with your hierarchy), I think you could create an abstract class which contains the properties you need, e.g.

public abstract class ViewableObject {
    public abstract int ID {get; set;}
    public abstract bool IsActive {get; set;}
    // etc
}

Then implement that with your normal classes (AreaType and so on), e.g:

public class AreaType: ViewableObject{
    public override int ID { get; set; }
    public override bool IsActive{ get; set; }
}

and make the view use the abstract class.

... Inherits="System.Web.Mvc.ViewPage<ViewableObject>"


One idea is to simply change your underlying tables. Combine AreaType and ModuleType into a single "WhateverType" table that contains a field identifying exactly what type it is. Then when you codegen your classes you'll have exactly one class to deal with.

However, there are other concerns and you should only do this if it makes sense in your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜