如何从数据库中删除实体? [英] How can I delete entity from data base?

查看:74
本文介绍了如何从数据库中删除实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我是Entity Framework 5的新手。我正在使用ASP.NET MVC的实体框架。

我有很多对多的关系。



  class  Garage 
{
public int GarageId {获取; set ;}
public string GarageAddress { get ; set ;}
public ICollection< Car>汽车{获取; set ;}
}

class Car
{
public int CarId { get ; set ;}
public string CarName { get ; set ;}
public ICollection< Garage>车库{获取; set ;}
}





汽车可以与不同的车库,车库也可以有很多车。

我的问题我不知道,我怎么能从一个车库删除车并把这辆车留在其他车库。此外,如果我只在一个车库删除汽车和这辆车,它应该从数据库中删除。



请提供一些例子。

谢谢

解决方案

实体框架删除 [ ^ ]



这里也是 [ ^ ]



删除多对多 [ ^ ]

这些是您可以了解的好地方。

如有任何其他疑问请发表评论..

谢谢

: )

Hi!

I'm new in Entity Framework 5. I'm using Entity Framework with ASP.NET MVC.
I have relationships Many-To-Many.

class Garage
{
public int GarageId{get;set;}
public string GarageAddress{get;set;}
public ICollection<Car> Cars{get; set;}
}

class Car
{
public int CarId{get;set;}
public string CarName{get;set;}
public ICollection<Garage> Garages{get; set;}
}



Car can be related to different garages, also Garages can have a lot of cars.
My problem I don't know, how can I delete car from one garage and left this car in other garages. Also If I delete Car and this Car only in one garage, it should deleted from DB.

Please provide some example.
Thanks

解决方案

Entity Framework delete[^]

Here also[^]

Delete Many to Many[^]
These are some good areas where you can get to know.
If any other queries please comment..
Thanks
:)


这篇关于如何从数据库中删除实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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