Im working with durandal 2 and breezejs.
I have some tables in my DB lets call them table1 and table2.
In the project i created a CRUD for table1 : viewmodels/table1crud.js + views/table1crud.html viewmodel and view that will connect to the DB using breeze, get data from table1, list the data, and offer a update/delete/add operations.
For table2 i can do the same, create another crud (view/viewmodel), BUT it can be not elegant, specially if i have more than 2 tables.
So my idea is to create ONE entitycrud viewmodel, with a constructor:
define(function(require){
var vm= function(entityType){
this.entityType= entityType;
this.activate = function(){...};
this.attached = function(){...};
etc ...
this.createEntity = function(){...};
etc ...
};
return vm;
});
Plus multiple views views/table1.html and views/table2.html.
So here is my question : is there any way to compose entitycrud with table1 or table2 using the entityType in the constructor ?
Something like :
<div data-bind="compose : {model : 'entitycrud("table1")', view : 'views/table1'}"></div>
<div data-bind="compose : {model : 'entitycrud("table2")', view : 'views/table2'}"></div>
This html code will not work of course, how can i do something similar ??
Thank you.
You can have a properties in another view model with the correct values like this (let's say cruds model) ,
define(function(require){
var vm= function(entityType){
this.crudTable1=new entitycrud("table1");
this.crudTable2=new entitycrud("table2");
};
return vm;
});
and then do the compose binding like this inside the cruds.html view,
<div data-bind="compose : {model : crudTable1, view : 'views/table1'}"></div>
<div data-bind="compose : {model : crudTable2, view : 'views/table2'}"></div>
Related
In my database, I have these two tables with a relationship :
I would like to get the whole content of the "assignee_kanban" column in "assigneekanban" table (which for now contains six names).
Here is the expression I use (in my "Kanban" controller using entity framework) :
public List<Kanban> LoadCard() {
return _context.Kanbans.Include(c => c.IdAssigneeKanbanNavigation).ToList();}
When I try to get the result in my razor page with :
#foreach (var name in Kanbans)
{
<tr>
<td>#name.IdAssigneeKanbanNavigation.AssigneeKanban1</td>
</tr>
}
unfortunatly, the result I get contains only three names : the three names corresponding to the three "id_assignee_kanban" that exist in the "kanban" table.
How can I get all the names contained in the "assignee_kanban" column ?
(I succeed to get the values using assigneekanban controller but for some reason, I want to use kanban controller with the navigation statement)
(project webassembly blazor using .net 6 aspnet hosted)
Thank you for your help.
Here is the content of the "kanban" table (I removed some no important columns for this problem) :
Here is the content of the "assigneekanban" table :
Here is the output :
As we can see, the name "Robert" corresponding to the id n°5 doesn't appaer in the result and the other names appear as many time they exist in the kanban table (of course, I can add a distinct close to avoid duplicate names but it doesn't bring the missing name !).
You need a second query to get all entries from the assigneekanban table. Your current implementation will only get those values from the assigneekanban that have a foreign key entry in the kanban table (Basically doing an INNER JOIN).
public async Task<List<Kanban>> LoadCardAsync()
{
return _context.Kanbans.ToList();
}
public async Task<List<AssigneeKanban>> LoadAssigneesAsync()
{
return _context.AssigneeKanbans.ToList();
}
public async Task LoadEverythingAsync()
{
Kanbans = await LoadCardAsync();
Assignees = await LoadAssigneesAsync();
}
Then in your Razor Page
#foreach (var assignee in Assignees)
{
<tr>
<td>#assignee.AssigneeKanban1</td>
</tr>
}
I have a table where it has the columns like IsAgreed, IsOther, IsEquipped. On the UI I am showing 3 check boxes where one can select single or multiple check boxes. The data is getting saved to db as expected. Now I am trying to select the data in entity framework as follows
from tbl context.TableNames select new {
Conitions= tbl.IsOther ? tbl.OtherText : tbl.IsAgreed ? "Agreed :
tbl.IsEquipped? "Equipped" : "" }
Which is giving only one selection when the multiple selection are made. I would like to concat and result the data so that it can be
OtherText, Agreed, Equipped
OtherText, Equipped
Agreed, Equipped
Is it possible to concatenate and give the expected output
You can create an array of strings based on conditions, after it can be formatted as desired. Please pay attention to the comment i wrote in the code sample.
var conditions = context.TableNames.Select(tbl => new
{
tbl.IsOther,
tbl.IsAgreed,
tbl.IsEquipped
})
.AsEnumerable() //Should be used with caution. Because it will load each record to memory. It also switches "LINQ to Entities" to "LINQ to Objects", so we can use string.Join.
.Select(c => new
{
Conditions = string.Join(", ", new string[] { c.IsOther ? "OtherText" : "", c.IsAgreed ? "Agreed" : "", c.IsEquipped ? "Equipped" : "" }.Where(s => !string.IsNullOrEmpty(s)))
});
I have to bind data for master and detail table coming from oData service in UI5 application.
This is my odata URI:
http://********************/sap/opu/odata/sap/ServiceName/Logheaderset?$filter=Object eq 'zwwxx6' and (Aldate ge (datetime'2015-07-14T00:00:00') and Aldate le (datetime'2015-07-23T23:59:59'))&$expand=NavMess
My requirement is I want to show child Entityset in detail table and parent Entityset in master table.
I am able to show parent Entityset in master table its working fine but dont know how to show child Entityset in detail table.
This is my code for detail table:
oTable1.setModel(oModel1);
oFilter1 = new sap.ui.model.Filter("Object", sap.ui.model.FilterOperator.EQ, "zwwxx6");
oTable1.bindItems("/Logheaderset/Messagelinesset", oTemplate1,null,[oFilter1]);
var oPage2 = new sap.m.Page({
title : "Table Test Page",
enableScrolling : true,
content : [ oTable1 ]
});
rPannel1.addContent(oTable2);
It looks like you are trying to implement an application that looks like our default case: https://openui5.hana.ondemand.com/#docs/guide/5ca68e6e62e6464a8103297fbc19cd9c.html
The idea is to start navigation when clicking on a master-entry. In the routeMatched handler of the default page you set the binding of the detail page according to the arguments you gave to the navigation.
Essentially you use the ID of your entity as a navigation argument and then you can do something like oDetailView.bindElement("/SomeEntitySet(" + sEntityId + ")") in the handler.
I have a table place that contain as column "state" (it is an Enum that can be 'ACTIVE' or 'INACTIVE')
I would like to know if there is a way with JPA2 that when i call placeRepository.findAll() or placeRepository.getOne(id) only select the row in the database that are marked as "ACTIVE" ?
something like this
List<Place> findByStateActiveOnly();
EDIT:
Bonus question:
I'am at the moment refactoring my project to be able to add a place (and other entities) in a pending state. Because I have added an extra column "state" now i have to add to ALL my queries this condition "AND p.state=my.package.State.ACTIVE" like this;
#Query("select p from Place p where p.idPlace = ?1 AND p.state=my.package.State.ACTIVE")
Isn't there a way to tell jpa to automatically select me if the state is ACTIVE ?
Thank you!
With Hibernate, you can try annotating your entity with #Where, something like this
#Entity
#Where(clause = "state = 'ACTIVE'")
public class Place {...}
Do with parameter:
public interface YourRepository ... {
List<Place> findByState(String state);
}
you will invoke like:
List<Place> placeList = youRepository.findByState("ACTIVE");
Context: I'm using the mongodb plugin, although this may have nothing to do with that.
Let's say I have two domain classes, Foo and Bar, where Foo hasMany Bar and Bar belongsTo Foo:
class Foo {
static hasMany = [bar:Bar]
}
class Bar {
static belongsTo = [foo:Foo]
}
I would expect that what would be stored would be a collection (or table) for Foo, an collection for Bar, and a FooBar collection that handles the mappings. Instead I am getting a Foo collection and a Bar collection, where Bar has a "foo" key. It seems like what is happening would be the expected result of only adding the belongsTo but omitting the hasMany...
A) Are my expectations simply incorrect and what is happening is the expected result?
B) If not A, is there something special I need to do to make it match my expectations?
Thoughts?
As we know mongodb is non relational database, that is why what is happening is correct, it doesn't create third table or collection for handling has many but as you are using mongodb plugin , you can query it like has many/belongsTo as you generally use with mysql. In your case db structure for foo would be:
{ "_id" : NumberLong(1), "version" : 0 }
and for Bar would be:
{ "_id" : NumberLong(1), "foo" : NumberLong(1), "version" : 0 }
And it will provide you, as it is cascade delete from parent to child like in case of using mysql
Hope It Helps:)