LINQ "equals" operator on nullable foreign key in NHibernate parent/child relationships -
background
My model looks like: (writing field instead of simplicity properties) < / P>
public square unit {public long id; The name of the public string; Public body guardian; } Required FNH Mapping
Map (x = & x; x.Name). Not. Elevated () Unikuke ("hair"); Reference (x = & gt; x.Parent) .Cascade.None () UniqueKey ("child"); The table 'unit' (id is not empty, the name is VARCHAR (255) not blank, PRNIID bit count, unique key ID (ID) (Name, parent_id)) And it's okay. I do not want to disagree among the children of the same institution (hence the two institutions of different parents can be the same name) Well, keep in mind that Parent_id Faucet What do I have to do?
I want to apply a check, instead of catching an exception before inserting a new unit in DB, I have to set a query (but I think this reduces the performance ...) to check whether the same Parents of a name and a new exception are present, so that the civilian exceptions can be thrown. Despite the performance, it still has a chance to learn something new about LINQ providers.
What do I do in plain old SQL
by id select id where name = ? And Parent_id =? and it correctly supports the NULL ID
Whatever I tried (and failed, otherwise I would not be here) var ExInput = (entityRepository.Query () from entity unit) entity.Name.ToLowerInvariant () == _newEntity.Name.ToLowerInvariant () & amp; Amp; Unit; mother-father. Eclipse (_newEntity.Parent) New {ParentName = entity Choose Guardian! = Null? Unit.name .name: null}). FirstOver Default (); I thought that NHibernate could be smart because it would accept a zero value as _newEntity.Parent and even enough Entity.Parent.Equals Anyway this is not a problem
error instead of a method call as an expression Code (which fails in case of zero) System.NotSupportedException: Boolean equivalent (System.Object) I know that NHibernate LINQ is not a complete LINQ provider and all methods of summer Udder does not Entity Framework support. So I can hope that I can work with by selecting the first institution by name and then can verify that both parents are tapes or if they equals () (I overloaded equals question
Given that I have NHibernate in the WHERE section Want to generate SQL as much as possible for me, what should I do? Can I use a different LINQ system to use the LINQ provider Whether or not I'm using X? I was thinking about expanding the LINQ provider, for which I have received some documents. It is my opinion that if the comparison of operations was identical Then we are just identifying their identity card (and if one of the institutions is null generated NULL identification in HQL). In this case, did anyone share Have any attempt to implement?
not equal query, just use entity.Parent == _newEntity.Parent . Your Linq query contains some additional differences of SQL you want to receive. Why do not you just use the following question?
var result = entity entity (entityRepository.Continue) from entity.Name == _newEntity.Name & amp; Entity.Parent == _newEntity.Parent select entity.Id) .Oir ();
Comments
Post a Comment