I think I found the cause of the problem, but I don't know how to solve it,
the scene is like this:
i used automapper 5.2 , Entity Framework 6 and use CreateMissingTypeMaps=true to save my CreateMap code
and i also have special map, so Initialize code like this
Mapper.Initialize(
a =>
{
a.CreateMissingTypeMaps = true;
a.CreateMap<query_template, QtGridUdfSearchTemplate>()
.ForMember(dest => dest.GridId, opt => opt.MapFrom(src => src.GRID_ID))
.ForMember(dest => dest.Guid, opt => opt.MapFrom(src => src.QUERY_TEMPLATE_GUID))
.ForMember(dest => dest.TemplateName, opt => opt.MapFrom(src => src.TEMPLATE_NAME))
.ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CREATED_BY))
.ForMember(dest => dest.IsDefault, opt => opt.MapFrom(src => src.IS_DEFAULT))
.ForMember(dest => dest.IsOffset, opt => opt.MapFrom(src => src.IS_OFFSET));
}
);
and map code
var source = DbContext.Set<query_template>().Find(keyValue);
var dest = Mapper.Map<query_template, QtGridUdfSearchTemplate>(source);
i get the dest all attribute is null ,when i remove a.CreateMissingTypeMaps = true; in Initialize , it is work , the dest all attribute can be map.
then i found the source Type is System.Data.Entity.DynamicProxies.query_template_80DE6B32EB08D5DFDD560580BB004DAD6A7FF27B94A3517A6BB4044B01FB8272 , so i think when i set CreateMissingTypeMaps , autoMapper auto create a map , not my create
many posts suggested context.Configuration.ProxyCreationEnabled = false; but i use LazyLoad. and don`t want to remove CreateMissingTypeMaps , because i have many normal type to map .
anyone can help me ?
Instead of putting ForMember(...), try:
ForMember<ObjectThatYouWantMap>(*Expression*);
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.
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?
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?
I have two Classes. "Product" and Product can have a number of objects of class "Attribute"
When someone edits the "Product" I would like to delete all Attributes associated with that product and recreate the new ones (second part works fine) but I'm getting a error which stops me removing the attributes.
public ProductMapping()
{
Id(x => x.Id);
Map(x => x.ProductName);
Map(x => x.Description);
Map(x => x.Quantity);
Map(x => x.Price);
Map(x => x.Live);
HasMany(x => x.Images)
.KeyColumn("ProductId")
.Cascade.All()
.Inverse();
HasMany(x => x.Attribute)
.KeyColumn("ProductId")
.Cascade.All();
}
And my Attribute mapping
public AttributeMapping()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Value);
Map(x => x.Live);
References(x => x.Product)
.ForeignKey()
.Column("ProductId")
.Cascade.SaveUpdate();
}
I'm not sure if my cascading is correct but I tried them all!
I've tried to get all the attributes and do
var AttRepository = GetRepository<ForSale.Domain.Attribute>();
foreach (var a in dbProduct.Attribute)
{
AttRepository.Delete(a);
}
removing each one individually, also tried doing a:
dbProduct.Attributes.Clear();
Again it doesn't succeed!
The error I get is
"Cannot insert the value NULL into column 'ProductId', table '{LocalFilePath}/PRODUCTS.MDF.dbo.Attribute'; column does not allow nulls. UPDATE fails.
The statement has been terminated."
dbProduct
You should map Product.Attribute as Inverse.