
NHibernate Can someone help me with the following Write an NHibernate application to insert and update the records of an employee table? Can someone write the complete program and pls explain all the files needed to write an NHibernate application? Assuming that you're setting up your sessionfactory / session correctly The recommended way to update data in NHibernate is to always use a transaction. Something like this: using(var session = sessionFactory.OpenSession()) using get you going. check these links http: / / www.comoke.com / index.php / 2010 / 05 / learn-nhibernate-lesson-3-insert-update-and-deletes / http: / / stackoverflow.com / questions / 1959355 / help-with-nhibernate-insert-update public IList<T> GetByExample<T> (T exampleInstance) { return _session.CreateCriteria( typeof (T)) .Add target) { ITransaction transaction = _session.BeginTransaction(); try { var res = GetByExample<T> (target); if ( res! = null && res.Count> 0 ) _session.SaveOrUpdate(target); else _session.Save(target); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw ; } finally { transaction.Dispose(); } } Can you give me the complete program? hi, try
ZZZZ", I do not get var MyMatchingTables = null, but rather I get zero hits (or .Count = 0). Must be built into Linq-to-Sql. I have been using it for years Must be built into Linq to Sql to never return null? myMyTableList = MyMatchingTables.ToList(); } catch (Exception ex) { Debug.WriteLine(ex.Message); / / never triggered, even if no match } return myMyTableList; } C# Discussions 1) Visual Studio 2008 (1) Visual Studio 2010 (1) Entity Framework (1) Visual Studio (1) NHibernate (1) Silverlight (1) How is a List<T> null? it is a collection. The collection can be insantiaed new and nothing put in it. Collection.count = 0. That's what is coming out of the query even if you did not I thought in Linq-to-Sql that is not allowed? So it will throw an exception (in the try / catch block)? Interesting, please confirm. One way around this null business of query to return. Attempting to use this null value may result in a null reference exception being thrown. You can easily confirm this behavior for yourself by writing some code. Use in Web applications are expensive. In the example I saw of your code, throwing that exception because something was null that you could have checked for being null without throwing an exception is bad programming IMHO. You might want to look at this. it is using controls
string" sonst wie Objekt von type "object" ? sp??ter wegen Falsch Typ Erkennung bekomme ich Exception: Das Objekt des Typs \ "System.Collections.Generic.List`1[System.String] \ " kann nicht in Typ obj_string, TM obj_math) { Type tt = obj_string.GetType(); / / richtig erkannt string type !{Name = "String" FullName = try { / / Exception! List<TS> obj_generic = (List<TS> )obj_math.GetType().InvokeMember("getSomeStringType", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj_math, null); } catch (Exception ex) { kann nicht in Typ \ "System.Collections.Generic.List`1[System.Object] \ " umgewandelt werden. Console wie hier "object" Typ obj_main.generic_func(obj_str, obj_math); } C# - German Discussions Visual Studio 2010 (1) NHibernate (1) BindingFlags.InvokeMethod (1) Activator.CreateInstance (1) BindingFlags.Default (1) Console.WriteLine (1) MakeGenericType (1 Hallo Marvin, ich werde deine Schreibvorschl??ge akzeptiert, danke f??r sie. Ich muss von NHibernate eine Funktion aufrufen die gib zur??ck eine IList<T> . Ich habe hier vereinfache dass einzelne Elemente zugreifen. Noch einmal NHibermate gib zur??ck List<T> for() { List <class_X> listClass_X = NHibernate(str_class_X); } Ich ??berg??be zum NHibernate nur class Name im string Format "str_class_X" und ich erwarte List<class_X> als zur??ck zu umgehen desto habe ich als linke Seite immer ein "object" Typ deklariert. object listClass_X = NHibernate(str_class_X); wie kann ich jetzt innerhalb listClass_X eine Methode ElementAt finden ? Typ Gr????, Milan. Hallo
Finally which ORM tool? .NET Framework Hi Currently there are some good ORM tools like NHibernate and LLBGL. Microsoft is working on it's own one ( I think it's name away and styart to learn new one?) - -Choosing current ORMs is nice? (Does for example NHibernate remain with .NET forever with support? What about future release of .NET? Is there any SQL Server 2008 (1) SQL Server (1) MySQL (1) Entity Framework (1) Visual Studio (1) NHibernate (1) Well, firstly I have no experience of LLBGL, so can't talk about that. NHibernate appeals to me due to it being open source, and I have had very positive backward compatibility: I wouldn't expect MS to release a version of .NET which breaks NHibernate or other libraries, and if it *does* I'm sure the NHibernate community will rally round to make the necessary changes. Jon currently we migrate our applications an anti-pattern ? Arne I would go for a well-known and respected framework like NHibernate or LLBLGen. There may be some consolidation in ORM frameworks, but those two are very making polymorphism often very difficult to use). Otherwise I've used both DevExpress XPO and nHibernate. XPO is much slicker in terms of generating and maintaining the underlying databases and also
PropertyType), null); and this works. When user enters letters to numeric cell, this line causes Exception. How to check that conversion can be performed ? Should I use try catch to catch this exception or is it possible to determine conversion error before raising exception ? Andrus. I don't think there's any equivalent of "TryChangeType", although you might want intended for known-list (StandardValues) lookups]. To try the conversion I would simply catch the exception (if one). You'd want to wrap the SetValue() too, since the property-setter could just as legitimately throw an exception for any reason it likes. Marc Marc, Thank you. I created the following method but obj)[propertyName]; Marc Marc, Thank you. If I enter characters to numeric column I get exception "eee is not a valid value for Decimal." at line object val = p.Converter.ConvertFromString add new calculated property to object at runtime or is there any other solution ? Andrus. Exception which I got: System.Exception was unhandled Message = "eee is not a valid value for Decimal." Source = "System" StackTrace: at