NHibernate - Deleting using nhibernate
Asked By j javier
09-Mar-10 01:28 AM
I have an organization class and a client class. Before deleting an organization I want to check if an organization is tied to a client/clients, if this is true deleting the organization should not be allowed. I just started learning nhibernated and was wondering how to go about checking if an org is tied to a client.
Thanks in advance,
Jane
Santhosh N replied to j javier

delete my OrderLines? I already tried DeleteRule = "CASCADE" on the EntitySet<OrderLine> (on the Order class), but it does not work. Here are two tests that illustrates the problem (i have orderId); Assert.AreEqual(3, ExecuteScalarSql<int> (countOrderLinesSql), } My classes look something like this: [Table] public class Order { [Column(Name = "Id", IsPrimaryKey = true)] public Guid OrderId { get; set; } [Association(OtherKey = "OrderId", DeleteRule = "CASCADE")] public EntitySet<OrderLine> OrderLines { get; set; } } [Table] public class OrderLine { private EntityRef<Order> order; [Column] private Guid OrderId; [Column(Name = "Id", IsPrimaryKey = true)] public order.Entity; } set { order.Entity = value; OrderId = value.OrderId; } } } Why does adding work, and not deleting? Any help is much appreciated. C# Discussions RepositoryDataContext.DataContext.SubmitChanges (1) RepositoryDataContext.DataContext.GetTable (1) NHibernate (1) BindingFlags.FlattenHierarchy (1) BindingFlags.GetProperty (1) BindingFlags.NonPublic (1) CanAddOrderLineToOrder (1) BindingFlags.GetField (1 code snip) Because adding isn't deleting. THe thing is that in-memory entity graph management doesn't have to reflect into it out" I fully understand why this is so hard. I've been working with NHibernate for several years, and I guess that I just expect this feature of an OR Mapper. In NHibernate you simply set CascadeStyle = AllDeleteOrphan, and it will delete an object if it is removed
the problem. . . When I link up the ObjectDataSource UpdateMethod to a method in the TypeName class that takes individual parameters (using '<UpdateParameters> . . . < / UpdateParameters> ') all is well. Eg. Runat = "server" EnableCaching = "false 2005 to link things up. 1. Adding attributes to the UpdateMethod method in the DataObjectTypeName class, as well as to the class itself. This only resulted in VS seeing the method (in the ObjectDataSource configuration wizard), but various method signatures. 3. Deleted the Asp.Net temporary files. 4. Changed namespaces, method names, class names. This proved that the compiler / runtime can find the class, but not the method. Any suggestions or help will be greatly appreciated. Regards. ASP.NET Discussions RecipeToolUI.MaterialComponent.UpdateMaterial (1) RecipeTool.Logic.Material (1) NHibernate (1) RecipeTool.Material (1) ASP.NET (1) IIS (1) DataObjectTypeName (1) SelectMethod (1) Are you wrong DataObjectTypeName to look for while trying to identify the right method to call in class specified by TypeName? In other words, the 'public void UpdateMaterial (Material m)' method in the TypeName class 'MaterialComponent' use one version of the 'Material' class, while the ObjectDataSource's DataObjectTypeName refers to
way, the right way. Thanks, Travis C# Discussions Visual Studio 2005 (1) Visual Studio (1) NHibernate (1) Oracle (1) ColumnAttribute (1) TableAttribute (1) DataAdapter (1) DataTable (1) I very rarely touch tools. Most recently (VS2008, .NET 3.5) LINQ-to-SQL would be of interest; but NHibernate is also very popular and has had more time to "bed in". Marc Travis, Why to use DataTable even when working with non- database information (since I use a base class that handles DataRow editing / extraction). I can of course deviate from the base class, but it makes the code seem dirtier to me (I like consistency). This sounds very my library that I wrote a few months ago. My library had an abstract base class. I had a small tool that took the database specification, generated recommended property types and names and allowed them to be customized. The generated class had Attributes such as TableAttribute and ColumnAttribute, and privilege properties. The abstract class managed properties using an IDataWrapper interface that could essentially pointed to an IDataRecord, DataRow, IDictionary to use DataTable even when working with non- database information (since I use a base class that handles DataRow editing / extraction). I can of course deviate from the base class, but
may differ significantly, from your existing database schema. For example, you can map a single class (or “entity”) to multiple tables / views, or map multiple classes to the same table / view handling with SQL Server databases only. 2)Uses the extension methods of System.Linq.Queryable class. 3)Introduced in .net Framework 3.0 4)DataContext is used for Database connectivity. 5 Access / Oracle / Excel etc. 2)Does not use the extension methods of System.Linq.Queryable class. 3)There since the .net Framework 1.0 4)SqlConnection / OleDbConnection are used for database handling with SQL Server databases only. 2)Uses the extension methods of System.Linq.Queryable class. 3)Introduced in .net Framework 3.0 4)DataContext is used for Database connectivity. 5 Access / Oracle / Excel etc. 2)Does not use the extension methods of System.Linq.Queryable class. 3)There since the .net Framework 1.0 4)SqlConnection / OleDbConnection are used for database ability to define more flexible mapping to existing relational schema, for example: • Mapping a single class to multiple tables • Mapping to different types of inheritance • Directly Modeling Many to Many relationships dbml file and give a name (assume “NW.dml”). Then there will be a DataContext class created. So you need to initialize the instance of an object. NWDataContext db = new NWDataContext CompanyName = "I do not know?" ; / / Save the changes to the database db.SubmitChanges(); } Scenario 5 +++++++ Deleting records from the database, ADO.NET Same as Scenario 3 LINQ to SQL using ( NorthwindDataContext