具有存储库模式的MVC,LINQ [英] MVC, LINQ with Repository Pattern

查看:65
本文介绍了具有存储库模式的MVC,LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC和LINQ的新手.我正在开发员工管理系统.

添加员工时,还需要在其他映射表中添加他的详细信息.

例如:一名雇员具有其基本详细信息,例如EmpID,EmpName等.

但是,另一个部门"表基于雇员"表中的EmpID具有与该部门相关的其他详细信息.

如何使用两个表中的信息,我需要将它们用于列表,创建,编辑,删除等.

请帮忙!!!

谢谢,
安库尔

如果不清楚,请让我知道,但是请帮忙.

I am new to MVC and LINQ. I am developing an Employee Management System.

When I add an Employee, I need to add his details in the other mapping tables also.

For ex: An employee has his basic details like EmpID, EmpName etc.

However the other Department table has other details related to his Department based on the EmpID from the Employee table.

How can I use the information from both the tables, I need to use them for Listing, Creating, Editing, Deleting etc.

Please help !!!

Thanks,
Ankur

If I am not clear, do let me know, but plz help

推荐答案

如果我正确理解您的想法,那么您有一个前端,您想在其中添加员工.从那里开始,您需要更新多个表.最好的选择是在数据库中创建一个存储过程,以接受数据参数.然后,存储过程将需要根据需要更新每个表.

如果要更新,则将创建一个更新过程,再次修改所有必要的表.

我希望这会有所帮助.
If I understand you correctly you have a front end where you would like to add employees. From there you need to update more than one table. Your best option would be to create a stored procedure in your database to accept the parameters of your data. The stored procedure will need to then update each table as required.

If you are updateing then you would create an update procedure, again to amend all tables necessary.

I hope this helps.


使用LINQ,事物的代码方面应该像对象一样工作(我假设Tables的意思是DB表,我对此不太清楚您的问题.您不应该将Employee看作是表中的东西,而恰好是表中存储的对象.要进行设置,您需要添加Department类型. >应该具有Department[s]属性(即一个或多个相关部门),反之亦然,然后您可以将这些属性作为普通对象访问并通过LINQ写入后备存储.
如果使用的是实体框架,则在部门模型中将部门表"添加为新类型时,只要您已正确规范化数据库,它就应为您添加具有正确基数的属性.使用LINQ to SQL,您可以在此处查看. microsoft.com/en-us/library/bb629295.aspx"target =" _ blank"title ="新窗口> ^ ]有关如何定义关系的信息.
With LINQ the code side of things should pretty much work just like objects (I''m assuming by Tables you mean DB tables, I''m a little unclear about your question. You shouldn''t think of Employee as something from a table as much as an obect that happens to be stored in a table.To set this up, you need to add a Department type. The Employee should have a Department[s] property (i.e. one, or more, related Department) and vice versa. You can then access the properties as normal objects and write to the backing store through LINQ.

If you are using the Entity Framework, if you add the Department Table as a new type in your entity model, it should add the properties for you with the correct cardinality, as long as you have normalised your Database properly. With LINQ to SQL you can look here[^] about how to define the relationship.


如果您要显示员工和其他数据,并且想要更新所有这些数据,则使用Entity Framework可为您提供一种简单的方法.

创建由各种组件组成的自己的对象-称为复合对象.因此,例如,执行此操作的方法是:

In the event you are displaying the employee and the additional data, and want an update of all that data, using Entity Framework gives you an easy approach.

Create your own object that is comprised of your various components -- known as a composite object. So a way of doing this for example would be:

   public class CompositeEmployee:Employee
   {
        public ObservableCollection<students> StudentList{get;set;}
        public Department {get;set;}
        public HumanResourceInfo{get;set;}
   }
</students>



在服务器端,将复合材料用于UpdateEmployee(CompositeEmployee)
它将分解成碎片并进行单独的更新.

您确实有一件事需要解决,那就是如何处理其中一项更新失败的事情.回滚更新或继续运行,返回已发生的异常/错误的列表.



In your server side you take the composite in for UpdateEmployee(CompositeEmployee)
and it will break out the pieces and do the separate updates.

You do have one thing to struggle with and that is how to handle things of one of the updates fails. Rollback the update or keep running returning a list of exceptions/errors that occurred.


这篇关于具有存储库模式的MVC,LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆