IndexedEmbedded not updating other side of relationship? - nhibernate.search

I have a one to many, let's say company-to-employees. I am trying to use [IndexEmbedded] on Employee's Company reference, so I can perform a employee query similar to: "Company.Name:IBM". When inserting the employee, this works fine. However, if I update the Company instance, the lucene index on the employee side does not get updated. The Lucene index does get updated if I update the employee in some other way in the same transaction.
I updated my NHibernate Search based on the advice from this question, but the index still does not get updated. Here's my relevant configuration:
c.SetListener(ListenerType.PostUpdate, new FullTextIndexEventListener());
c.SetListener(ListenerType.PostInsert, new FullTextIndexEventListener());
c.SetListener(ListenerType.PostDelete, new FullTextIndexEventListener());
c.SetListener(ListenerType.PostCollectionUpdate, new FullTextIndexCollectionEventListener());
c.SetListener(ListenerType.PostCollectionRecreate, new FullTextIndexCollectionEventListener());
c.SetListener(ListenerType.PostCollectionRemove, new FullTextIndexCollectionEventListener());
Any advice much appreciated.

Related

Update entity with OneToMany relationship with JPA/Spring

I've been researching this for a while and still couldn't find a satisfactory answer for my problem.
I have an entity on my postgres DB (product) that has a ManyToOne relationship with another entity (Dun).
Each product may have N duns.
On my PUT endpoint, the desired behavior would be:
Every time I update a product, it replaces all the duns with the ones provided on the endpoint.
Is there any way to handle it automatically by Hibernate/JPA?
In order to make it easier to test and explain the issue, I've uploaded a project on Github on the following link https://github.com/brunapereira/jpaexample
If there's no way to handle it automatically by JPA, what's the best way to solve it with code?
Thanks in advance,
First, you need to remove Duns by product id, then get the product by id, add the new duns then save back.

How to create a quick search in CRM that spans multiple entities with grouped conditions

We are a housing association with a large CRM system (2016 & SP1). We have a new requirement that requires our users to be able to search for people who are current (ie not previous) occupants or residents or who are not residents (eg contractors)
For this purpose, we need to search the Person entity which has a related Tenancy entity. Person has TenancyType field with possible (option set) values Occupant, Resident, Contractor. Tenancy has TenancyStatus field with possible (text) values Current and Previous.
We tried using the following filter criteria in the quick view on the Person entity:
thinking that it would return all people who are not previous residents. However we noticed that it would filter out contractors because contractors do not have related tenancy records.
We needed to change the criteria to return all contractors OR all residents and occupants with no previous tenancy. So we changed it to the following:
at which point we got stuck because we noticed that it was not possible to AND together the second and the third conditions as the third one is a related entity.
We are wondering what the best way is to achieve the above bearing in mind that we do not want a separate view for each condition, eg one for residents, one for none residents, etc.
Any help or suggestion is greatly appreciated.
It is not possible to do this with a single query.
Instead, you can use two queries. If you do not want to do that, then using reports (as suggested by Alex) or a BI-solution would be other possibilities.
Thanks to everyone here who spent time answering my question. The following describes the correct answer:
https://community.dynamics.com/crm/f/117/p/241352/666651#666651

How to create new query method at repository with or without ElasticSearch and Spring Boot?

I have 2 models, one called Employee and another one User,
Employee has one field pointing to User, one to one relationship.
My problem is that i need one query method to find the Employee that has the user with certain id. I need to find the Employee with certain User id.
I know the default query methods: .findOne, .findAll, but i need to create one, alright? how i can do that? i searched a lot but probably i am missing something. I didn't found how to do a query like that.
Thanks

Update EF model - DB at different location

I am very new to EF programming.
My application gets the data from existing database. (DB first)
Now I have come to situation where I want to update my model to newer DB. basically the core schema is same as previous but has some modification in the table.
When I change the DB name for app.config and update the model it gives list of error
have I missed something?
When you do an update it merges the model you have with the DB that you update from. Additional columns are added to your existing entities but columns that you have removed from the DB are not removed from your entities and you need to remove these mappings yourself.
If you know which tables have columns removed it sometimes easier to delete the entity from your model and then do an update to reload it from the DB.
If you've don't know what tables or there have been many then it may be easier to delete all entities from your model and just do a full Update to reload the the new DB structure.

Linq doubts with DB context

Hi I have a question that is braking my mind for some days.
I have my SQL server Database and my C# application.
In the DB I have differemt tables, let me show you a simple ex
Tables:
Person
Relationship
City
Business Rules:
The person are from a City, so the person has IdCity
A person has a relationship with other person, and about that relationship you need to save the starting date.
In other projects I already did something like that, but in this proyect this is not working for me.
When I retrieved with LinQ the information about the person, the city is not coming, and an error appears when I try "person.city.description", for ex.
I try using Include("City") in the linq query, but it didn't work. Besides that, I don't know how to manage the circular reference to the person to person relationship.
One important thing, that I think that can be the problem, is that I rename all the tables from the DataModel, for example, the table in database is called Prd_City, so I change the Name and the Entity Set Name for City in c# project. So in the included I have to use the real table name, in other case the query fail, but if I use the real name nothing happens.
using (var context = new MyContext())
{
List<Person> oPeople = (from p in context.Person.Include("Prd_City")
select p).ToList();
return oPeople ;
}
Any help will be welcome.
Thanks!
"It didn't work" is never a good description of your problem. But from the rest of your question I can infer that Person has a navigation property named "Prd_City", while you expected it to be "City". The thing is: you renamed the entities, but not the navigation properties in the entities.
My advice (for what it's worth): it seems that your work database-first. If you can, change to code-first and manually map the POCO classes to their table names, and properties to their database columns. It may be a considerable amount of work (depending on the size of your data model), but after that you will never run the risk of EF "un-renaming" your entities. Besides, the DbContext API is easier to use than ObjectContext. Currently, it's the preferred EF API.

Resources