Asp Net Core - Error persisting Value Object - asp.net-core

I am trying to persist a value valuobject from address and I get the error below, I am using postgres and I already tried to map this class in several ways, I saw that some people had similar problems but I did not find the solution.
I only encounter this error when using ef core
System.InvalidOperationException: 'The entity of type 'EmpresaModel' is sharing the table 'Empresa.Empresa' with entities of type 'EnderecoEmpresa', but there is no entity of this type with the same key value that has been marked as 'Added'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.'
builder.OwnsOne(e => e.EnderecoEmpresa, a =>
{
a.Property(p => p.Bairro).HasMaxLength(50)
.HasColumnName("Bairro")
.HasDefaultValue("");
a.Property(p => p.CEP).HasMaxLength(10)
.HasColumnName("CEP")
.HasDefaultValue("");
a.Property(p => p.Complemento).HasMaxLength(60)
.HasColumnName("Complemento")
.HasDefaultValue("");
a.Property(p => p.IdMunicipio)
.HasColumnName("MunicipioId");
a.Property(p => p.IdUF)
.HasColumnName("UfId");
a.Property(p => p.Logradouro)
.HasColumnName("Logradouro").HasMaxLength(60)
.HasDefaultValue("");
a.Property(p => p.Numero)
.HasColumnName("Numero").HasMaxLength(10)
.HasDefaultValue("");
});

Related

UnSupportedEntityException when trying to create/render records containing slug extension

I am trying to implement slugs in my bundle, but when i try to create a record and run my message consumer i get the following error:
Unexpected exception occurred during Direct URL generation ["exception" => Oro\Bundle\RedirectBundle\Exception\UnsupportedEntityException { …}] ["processor" => "Oro\Bundle\RedirectBundle\Async\DirectUrlProcessor","message_id" => "oro.6256de2124b630.96491198","message_body" => ["createRedirect" => true,"id" => [3],"class" => "Phpro\OroBundleBlogBundle\Entity\BlogPostCategory"],"message_properties" => ["oro.message_queue.client.topic_name" => "oro.redirect.generate_direct_url.entity","oro.message_queue.client.queue_name" => "oro.default","oro.security.token" => "organizationId=1;userId=1;userClass=Oro\Bundle\UserBundle\Entity\User;roles=ROLE_ADMINISTRATOR"],"message_headers" => ["content_type" => "application/json","message_id" => "oro.6256de2124b630.96491198","timestamp" => "1649860129","priority" => "2"],"elapsed_time" => "34 ms","memory_usage" => "107.57 MB"]
The slugs are stored, but the use of the get_slug_urls_for_prototypes twig filter results in the following error An exception has been thrown during the rendering of a template (""). Again because of the UnsupportedEntityException
Am i missing some configuration?
As mentioned in the OroCommerce documentation the entity must implement the interface to support slugs. Make sure you fulfilled this requirement.

How to request facets from AWS CloudSearch via the PHP v2 SDK?

I am using v2 of the PHP SDK for interfacing requests to AWS CloudSearch. The documentation is here, however details and examples are somewhat lacking. I need to include facets in my search. It is clearly asking for a string but it is not clear exactly how the string should be formatted.
$cloudSearchDomainClient->serach([
'filterQuery' => $filter,
'query' => $query,
'queryParser' => 'lucene',
'facet' => '???'
]);
I have tried, for example:
'facet' => 'field1,field2,field3'
'facet' => 'facet.fieldname={sort:'count',size:5}'
'facet' => 'fieldname={sort:'count',size:5}'
(Some permutations based on examples in the non-sdk request descriptions here)
The appropriate syntax appears to be a string representing a javascript object.
For the default sort/count:
'facet' => '{fieldname:{}}'
To specify sorting options:
'faceet' => '{fieldname:{'sort':'count',size:5}}'
To request multiple facets:
'facet' => '{field1:{},field2"{}}"
Etc.

Foreign keys in CORE

Using Community-2017 and imported the database but I am having an issue with the foreign keys. I have an error about not being part of the ICollection, and do not know what the means.
entity.HasOne(d => d.SendObNoNavigation)
.WithMany(p => ***p.EntSendingBuilding)*** <---
.HasForeignKey(d => d.SendObNo)
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("FK_entSendingBuilding_entBuilding");
This is because property EntSendingBuilding does not implement ICollection<>, for example, it is not an List<>.

RavenDB Query: Have to use Customize() instead of Include()

I'm getting an error that I'm exceeding the number of requests allowed per session (30) when using this query (using Include instead of Customize):
ApplicationServer appServer = QuerySingleResultAndSetEtag(session => session
.Include<ApplicationServer>(x => x.CustomVariableGroupIds)
.Include<ApplicationServer>(x => x.ApplicationIdsForAllAppWithGroups)
.Include<ApplicationServer>(x => x.CustomVariableGroupIdsForAllAppWithGroups)
.Include<ApplicationServer>(x => x.CustomVariableGroupIdsForGroupsWithinApps)
.Include<ApplicationServer>(x => x.InstallationEnvironmentId)
.Load <ApplicationServer>(id))
as ApplicationServer;
Note, the error occurs on this line, which is called for each AppWithGroup within an application:
appGroup.Application = QuerySingleResultAndSetEtag(session =>
session.Load<Application>(appGroup.ApplicationId)) as Application;
However, this query (using Customize) doesn't create extra requests:
ApplicationServer appServer = QuerySingleResultAndSetEtag(session =>
session.Query<ApplicationServer>()
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIds))
.Customize(x => x.Include<ApplicationServer>(y => y.ApplicationIdsForAllAppWithGroups))
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForAllAppWithGroups))
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForGroupsWithinApps))
.Customize(x => x.Include<ApplicationServer>(y => y.InstallationEnvironmentId))
.Where(server => server.Id == id).FirstOrDefault())
as ApplicationServer;
However, the above query causes an error:
Attempt to query by id only is blocked, you should use call
session.Load("applications/2017"); instead of
session.Query().Where(x=>x.Id == "applications/2017");
You can turn this error off by specifying
documentStore.Conventions.AllowQueriesOnId = true;, but that is not
recommend and provided for backward compatibility reasons only.
I had to set AllowQueriesOnId = true because it was the only way I could get this to work.
What am I doing wrong in the first query to cause the includes not to work?
By the way, another post had the same issue where he had to use Customize. I'd like to do this correctly though.
I'm not sure why the load isn't doing this for you, What version of raven are you on? I just tested this in Raven 2.5 build 2700 and the include is bringing back the information for me in a single request.
Anyway, with the load not working quite like i would expect, i would switch to a set of lazy queries to get what you want in 2 server round trips. http://ravendb.net/docs/2.5/client-api/querying/lazy-operations.
Another option that might work out better for you, (depending on what you are really doing with all of that data) is a transformer. http://ravendb.net/docs/2.5/client-api/querying/results-transformation/result-transformers?version=2.5
Hope that helps.

Fetching Amazon buyback ("trade-in") price

Is there a way to get the Amazon buyback (aka "trade-in") prices for textbooks through an API? I've searched around for a while but can't find a clue how people are getting this for their websites..
Here is the Amazon BuyBack program: amazon.com/buyback
Here is an example buyback URL: http://www.amazon.com/gp/search/s/ref=tradeinavs?url=rh%3Dn%3A2205237011%26i%3Dtextbooks-tradein&field-keywords=978-0321614018&Go.x=10&Go.y=17
I'm aware that I could just fetch the pages and parse the HTML, but if there is some way to get it through an API or whatever, I'm sure Amazon would prefer that to just parsing the page (also it would be faster to query).
The Product Advertising API has it in the ItemAttributes section when you do an ItemLookup search, as shown by this sample call (I believe this is perl, but just to show you a sample):
my $request = {
Service => 'AWSECommerceService',
Operation => 'ItemLookup',
Version=>'2010-11-01',
ItemId => $itemId,
ResponseGroup => 'ItemAttributes',
};
snip
'ASIN' => '0136100570',
'ItemAttributes' => {
'NumberOfItems' => '1',
'IsEligibleForTradeIn' => '1',
'TradeInValue' => {
'Amount' => '3550',
'CurrencyCode' => 'USD',
'FormattedPrice' => '$35.50'
},
'ListPrice' => {
'Amount' => '18900',
'CurrencyCode' => 'USD',
'FormattedPrice' => '$189.00'
Source: https://forums.aws.amazon.com/message.jspa?messageID=212679