EF generate two FK by one relationship - entity-framework-6

EF 6.1.3
Mapping
var b = mb.Entity<PAYMENT_INVOICE>();
b.ToTable("T_PAYMENT_INVOICE");
b.HasPrimaryKey(x => x.Id);
b.Property(x => x.OrdersSumm).IsRequired();
b.Property(x => x.MargaSumm).IsRequired();
b.Property(x => x.DeliverySumm).IsRequired();
b.Property(x => x.PaySumm).IsRequired();
b.Property(x => x.CreateDate).IsRequired();
b.Property(x => x.Sended).IsRequired();
b.Property(x => x.LastError).IsOptional();
b.HasOptional(x => x.Payment).WithMany(x => x.Invoices).HasForeignKey(x => x.PaymentId);
b.HasRequired(x => x.Client).WithMany().HasForeignKey(x => x.ClientId);
b.HasRequired(x => x.Purchase).WithMany(x => x.Invoices).HasForeignKey(x => x.PurchaseId).WillCascadeOnDelete(false);
Why generate this key and column? Both are equal.
I remove column PURCHASE_ID and FK_dbo.T_PAYMENT_INVOICE_dbo.T_PURCHASE_PURCHASE_Id.
When I save PAYMENT_INVOICE I get an error:
Invalid column name 'PURCHASE_Id'
I do not need a second key, what is my mistake?

Related

Search list result null prevPageToken

I'm trying to get videos from my channel using search function. Response include only nextPageToken, but no prevPageToken. prevPageToken is null always, even if I'm listing other pages using nextPageToken. I use an access_token param from Google Oauth.
My request:
$searchResponse = $youtube->search->listSearch('snippet', array(
'forMine' => 'true',
'order' => 'date',
'pageToken' => $pageToken,
'type'=>'video',
'maxResults' => '10',
'q' => $searchQuery,
));
Result:
Google_Service_YouTube_SearchListResponse Object
(
[collection_key:protected] => items
[etag] => "XXX"
[eventId] =>
[itemsType:protected] => Google_Service_YouTube_SearchResult
[itemsDataType:protected] => array
[kind] => youtube#searchListResponse
[nextPageToken] => Cib3-ZrgSf____9uWHdEYVNIVnlOVQD_Af_-blh3RGFTSFZ5TlUAARAPIbmtEhE6-iWlOQAAAAC2H2UGSAFQAFoLCdIYcGeU2-YsEAJgyOjNygE=
[pageInfoType:protected] => Google_Service_YouTube_PageInfo
[pageInfoDataType:protected] =>
[prevPageToken] =>
[regionCode] =>
[tokenPaginationType:protected] => Google_Service_YouTube_TokenPagination
[tokenPaginationDataType:protected] =>
[visitorId] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[pageInfo] => Google_Service_YouTube_PageInfo Object
(
[resultsPerPage] => 5
[totalResults] => 55
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
Thank you for your ideas!
Petr
UPDATE
This problem is only if is set param forMine. But I need show only my videos...

Yii2 join 6 tables + dropdown filter in grid

I have the following tables/models: A, B, C, BC, D, BCD
(A:B 1:N) Connecting table D to BCD would be no problem. However I would like to filter key attributes as dropdown from A, B, C and D to find results in BCD (because in the end I need BCDid). In BCD next to BCid and Did I can store of course Aid, Bid and Cid, and it would seem to me quite an easy workaround, however I know it's totally against db normalisation. Is there another, better way (with eager loading of course)?
I've now this in BCD:
public function getB() {
return $this->hasOne(\app\models\B::className(), ['id' => 'Bid'])
->via('BC');
}
and it seems to work, but it's not eager loading.
And how do I get to model A? can I define it like this in BCD?:
public function getA() {
return $this->hasOne(\app\models\A::className(), ['id' => 'Aid'])
->via('BC')
->via(B);
}
It doesn't really work yet.
This way it works (BCSearch):
public function search($params) {
$query = BC::find()->joinWith('A', true)->joinWith('C', true);
Relation A in BC defined with "via". Dropdown filter also works.
But I still don't know how to achieve one more level deep into db structure.
This way it seems to work fully:
models/BCDSearch.php
public function search($params) {
$query = BCD::find()
->select([
'BCD.id',
'BCD.amount',
'A.id AS A_Id',
'A.name AS A_name',
'B.name AS B_name',
'B.name2 AS B_name2',
'C.name AS C_name',
'D.name AS D_name',
])
->leftJoin('BC', 'BC.id = BC_Id')
->leftJoin('B', 'B.id = B_Id')
->leftJoin('A', 'A.id = A_Id')
->leftJoin('C', 'C.id = C_Id')
->leftJoin('D', 'D.id = D_Id');
$query->andFilterWhere([
...
'A.id' => $this->A_Id,
'B.name' => $this->B_name,
'B.name2' => $this->B_name2,
'C.name' => $this->C_name,
'D.name' => $this->D_name,
]);
public function rules() {
return [
...
[[... 'A_Id', 'B_name', 'B_name2', 'C_name', 'D_name'], 'safe'],
];
}
models/base/BCD.php:
class BCD extends Whatever {
public $A_Id;
public $A_name;
public $B_name;
public $B_name2;
public $C_name;
public $D_name;
views/BCD/index.php:
GridView::widget([
'layout' => '{summary}{pager}{items}{pager}',
'dataProvider' => $dataProvider,
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last')],
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'A_Id',
'value' => 'A_name',
'filter' => yii\helpers\ArrayHelper::map(app\models\A::find()->all(), 'id', 'name')
],
[
'attribute' => 'B_name',
'value' => 'B_name',
'filter' => yii\helpers\ArrayHelper::map([['id' => 'name1', 'name' => 'name1'], ['id' => 'name2', 'name' => 'name2']], 'id', 'name')
],
[
'attribute' => 'B_name2',
'value' => 'B_name2',
'filter' => yii\helpers\ArrayHelper::map([['id' => 'name2_1', 'name' => 'name2_1'], ['id' => 'name2_2', 'name' => 'name2_2']], 'id', 'name')
],
[
'attribute' => 'C_name',
'value' => 'C_name',
'filter' => yii\helpers\ArrayHelper::map(app\models\C::find()->all(), 'C_name', 'C_name')
],
[
'attribute' => 'D_name',
'value' => 'D_name',
'filter' => yii\helpers\ArrayHelper::map(app\models\D::find()->all(), 'D_name', 'D_name')
],
'amount',
...
hope this helps others. It was not easy to figure out (at least for me) this basically easy solution. I don't know why but so far I couldn't find any relevant info on the web like this.

Automapper can not map IEnumerable<T>

Thats the exception I get:
Missing type map configuration or unsupported mapping.
Mapping types:
CompanyViewModel -> Company
Razor.Sample.ViewModels.CompanyViewModel.CompanyViewModel -> Model.Company
Destination path:
CompanyListViewModel.Companies.Companies.Companies0[0]
Source value:
Razor.Sample.ViewModels.CompanyViewModel.CompanyViewModel
When I run this code:
var companyViewModels = Mapper.Map<IEnumerable<Company>, IEnumerable<CompanyViewModel>>(companies);
var companyListViewModel = Mapper.Map<IEnumerable<CompanyViewModel>, CompanyListViewModel>(companyViewModels);
Thats my mapper profile:
CreateMap<IEnumerable<CompanyViewModel>, CompanyListViewModel>()
.ForMember(dest => dest.TopRankings, o => o.MapFrom(src => src.Select(c => c.TopRanking)))
.ForMember(dest => dest.TotalCompaniesWithOpenPositions,
o => o.MapFrom(src => src.Count(c => c.HasOpenPositions == true)))
.ForMember(dest => dest.TotalEmployees,
o => o.MapFrom(src => src.Select(c => c.NumberOfEmployees).Sum<int>(s => s)))
.ForMember(dest => dest.Companies, o => o.MapFrom(src => src.Select(c => c)));
I know that the CreateMap should not have the IEnumerable<T> but HOW then can I map from each CompanyViewModel and its properties to create a Sum with LINQ for example and assign it to the dest.TotalEmployees? I need the enumerable in the profile not in the mvc controller where I call the .Map<T>().

how to get value from wsdl returned data in PHP?

Below is the data I'm getting from wsdl response... I need to get the separate value for example how to get the firstname from this array...Please anyone help me...
GetReportResponse Object ( [GetReportResult] => MBPeopleSearchRs_Type Object ( [MsgRsHdr] => MsgRsHdr_Type Object ( [RqUID] => {4DB2AD23-228A-465F-938D-BE072CED61C4} [Status] => Status_Type Object ( [StatusCode] => 0 [ServerStatusCode] => [Severity] => Info [StatusDesc] => OK [AdditionalStatus] => ) ) [Subject] => Subject Object ( [RefNum] => [PersonInfo] => PersonInfo_Type Object ( [PersonName] => PersonName_Type Object ( [LastName] => JANARDHANAN [FirstName] => SENTHINBABU [FullName] => [MiddleName] => [TitlePrefix] => [NameSuffix] => [Nickname] => [LegalName] => [MaidenName] => [OfficialTitle] => [Source] => MB [EffDt] => 2013-05-24 ) [ContactInfo] => ContactInfo_Type Object ( [ContactPref] => [PhoneNum] => [ContactName] => [EmailAddr] => [URL] => [PostAddr] => PostAddr_Type Object ( [PreDirection] => [Addr2] => [PostDirection] => N [Addr3] => [StreetType] => AVE [Addr4] => [StreetName] => LEXINGTON [Apt] => APT 4203 [StreetNum] => 4150 [Addr1] => [City] => SAINT PAUL [StateProv] => MN [PostalCode] => 55126-6131 [County] => RAMSEY
I suggest using a framework for this. CXF is a good choice if you write Java.
http://cxf.apache.org/
edit: since you work with php, take a look here: PHP SOAP client Tutorial/Recommendation?

ruby add new key-value pair to nested hash

Suppose we have a nested hash here.
a = {:"0" => {:CA => {:count => 10}}}
if we want to add a new hash pair to that hash, say
a = {:"0" => {:NY => {:count => 11}}}
and let it become
a = {:"0" => {:CA => {:count =>10}, :NY => {:count => 11}}}
what should I do?
I've tried
a[:0][:NY][:count] = 11
but get the error "undefined method `[]=' for nil:NilClass (NoMethodError)"
You are getting the nil:NilClass error because you are trying to set a key of hash that doesn't exist yet. You need to create the hash that is the value of the key :NY.
a[:"0"].merge!({:NY => {:count => 11}})
or
a[:"0"][:NY] = {:count => 11}
My guess is that you want to do something like this.
a = {:"0" => {:CA => {:count => 10}}}
b = {:"0" => {:NY => {:count => 11}}}
a[:"0"][:NY] = b[:"0"][:NY] #=> {:"0"=>{:CA=>{:count=>10}, :NY=>{:count=>11}}}
You could also take advantage of merge
a = {:"0" => {:CA => {:count => 10}}}
b = {:"0" => {:NY => {:count => 11}}}
a[:"0"] = a[:"0"].merge(b[:"0"]) #=> {:"0"=>{:CA=>{:count=>10}, :NY=>{:count=>11}}}

Resources