I'm trying to bind to a CollectionViewSource nested property (CVS.View.Groups.Count) and it doesn't seem to work in code :
Binding binding = new Binding();
binding.Path = new PropertyPath("View.Groups.Count");
binding.Mode = BindingMode.OneWay;
binding.Source = CVS;
BindingOperations.SetBinding(this, ValueProperty, binding);
But it's working well in WPF/xaml.
<DataTrigger Binding="{Binding Path=CVS.View.Groups.Count, Mode=OneWay}" Value="1">
So I'm wondering what is the difference between these both approach and what is wrong in code way binding. Meanwhile this kind of code is working well on no-nested property when it's a simple dependency property in a dependency object, so I suppose there is a problem with provided PropertyPath..
Any help would be appreciated.
I succeeded in resolve the problem by changing the binding source. Instead of passing the dependency object directly I create a Windows.Forms.BindingSource with the dependency object and I set this object as source of binding. In this way the binding is now working well.
Binding binding = new Binding();
binding.Path = new PropertyPath("View.Groups.Count");
binding.Mode = BindingMode.OneWay;
System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource(DevicesInAlarmCVS, null);
binding.Source = bs;
BindingOperations.SetBinding(this, ValueProperty, binding);
It seems to be linked to a change in .NET framework 4.0 :
Does data binding support nested properties in Windows Forms?
Hope that's can help
Related
In my project I am trying to integrate Telerik reports. I used below code to bind data to my report:
#{
var typeReportSource = new TypeReportSource() { TypeName = typeof(Invoice).AssemblyQualifiedName };
typeReportSource.Parameters.Add("OrderNumber", Model.SelectedInvoice);
}
#(
Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(typeReportSource)
.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
)
Now I want to bind a static list to Report that must be generated at controller due to project structure. Is it possible bind Report to static list? I found that .ReportSource() had overload which take ReportSource as parameter but it is obsolete now. I tried to use the obsolete method as:
#{
var reportSource = new Invoice();
reportSource.DataSource = myData;
}
#(
Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(reportSource)
.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
)
but it is shows message No Report. Currently I am passing my data as Report Parameter but I think passing large data as report parameter may be a bad practice. Is there any better way to pass static collection to Terik Html5 Report?
recently I started my adventure with F#. I'm trying to create F# library that I will use in my C# projects.
Now I'm facing the problem that I have two types definitions that (as I wish) could use themselves (I'm trying to create fluent API for c# usage).
How I want to use it in c# (simplified example).
Shopping shopping = new Shopping();
Stuff[] stuff = shopping.GoTo("Wallmart").Buy(new [] { "Candies", "Ice cream", "Milk" }).GoTo("Drug store").Buy(new [] { "Anvil" }).GetStuff();
Now I have two types (in separted files):
type ShopResult(someContext: ShoppingContext) =
//some logic
member this.GoTo shopName = new ToDoResult(someContext)
type ToDoResult(someContext: ShoppingContext) =
//some logic
member this.Buy what = new ShopResult(someContext)
Now the file order causing compilation error and I'm wondering if there's any solution for my case? or have I to drop the fluent api idea?
Put both types in the same file and change the definitions to the following:
type ShopResult(someContext: ShoppingContext) =
//some logic
member this.GoTo shopName = new ToDoResult(someContext)
and ToDoResult(someContext: ShoppingContext) =
//some logic
member this.Buy what = new ShopResult(someContext)
For more information, see the section 'Mutually Recursive Types' in the language reference on MSDN.
I've noticed that in the metadata there's an object entityType but also an object enumType.
We use manager.metadataStore.getEntityType() to access the metadata of an Entity.
How can we do it for a given enum ? How would I create the enum on the client side out of the metadata ?
Also, when I assign an enum value to a property, I'd like to to it by name instead of by value.
For instance, assuming that Status is of type myEnum:
myEntity.Status = myEnum.Valid;
instead of
myEntity.Status = 1;
Does breeze have any helper function to access the values of an enum ?
This issue is still open as I write. But you might want to take a look at the work-around described in the answer to this SO question.
I am assuming that you are talking about data properties that are defined as .NET enums on the server, and you want additional metadata about these properties to be made available on the Breeze client.
Unfortunately, Breeze does not yet support any metadata on enum types other than the name of the .NET type backing the enum value. This is the 'enumType' property that will appear on any dataProperty that is backed by an .NET Enum on the server. (We do need to document this better)
Please add a feature request for this to the Breeze User Voice. It's a good idea and we do take these suggestions very seriously.
Well this is not exact solution to your question but definitely can help people who are generating metadata offline.
I am using NancyFx(No EF) + Breeze + AngularJS for my web project and generating breeze metadata offline(using EF methods at development) and then using it in js file.
I also encountered similar situation where I want to get all Enum values to bind dropdowns and to display EnumName corresponding to EnumValue(Id). I searched over net but there was not much as per my scenario.
So I have written raw JS methods
1. To extract all enums and their values(Id & Name) in a JS dictionary(associated array) from metadata.
var enumDictionary = {};
JSON.parse(window.app.metadata).schema.enumType.forEach(function (enumType) {
var newEnumValues = [];
enumType.member.forEach(function (enumValue) {
var newEnumValue = { id: enumValue.value, name: enumValue.name };
newEnumValues.push(newEnumValue);
});
enumDictionary[enumType.name] = newEnumValues;
});
I created a method to get all enum values for a specific enum. This will be used for binding a dropdown.
function GetEnumDictionary(enumName) {
return enumDictionary[enumName];
}
Another method I created to get specific Enum name on basis of value.
function GetEnumDictionaryValue(enumName, enumValueId) {
var result = null;
enumDictionary[enumName].some(function (enumValue) {
if (enumValue.id == enumValueId) {
result = enumValue.name;
return;
}
});
return result;
}
How would one translate the following composite key query:
?stale=false&connection_timeout=60000&limit=10&skip=0&startkey=["Default",{}]&endkey=["Default"]&descending=true
to couchbase .net api when using F#. I found a similar using C# LINQ here
Couchbase .Net Library complex startKey/endKey types, but how can I accomplish the same using F#?
The missing parts are the ???
let result = myView.Descending(true).Stale(StaleMode.False).Limit(limit).StartKey( ??? ).EndKey( ??? )
Any help would be appreciated.
It appears that you're asking how to create an array in F#. To declare an object array in F# do this:
let (startKey: Object array) = [|35; 23; new Object()|]
let (endKey: Object array) = [|35; 23|]
Note that normally the type specification isn't needed, but since you're mixing types in the array, the compiler will assume the type of the first object in the array (int) and so the new Object() would cause a compile error. Adding the type specification fixes that issue.
let result = myView.Descending(true).Stale(StaleMode.False).Limit(limit).StartKey( startKey ).EndKey( endKey )
In EF4, this was not easily possible. You either had to degrade to classic ADO.NET (DataReader), use ObjectContext.Translate or use the EFExtensions project.
Has this been implemented off the shelf in EF CTP5?
If not, what is the recommended way of doing this?
Do we have to cast the DbContext<T> as an IObjectContextAdapter and access the underlying ObjectContext in order to get to this method?
Can someone point me to a good article on doing this with EF CTP5?
So i got this working, here's what i have:
internal SomeInternalPOCOWrapper FindXXX(string xxx)
{
Condition.Requires(xxx).IsNotNullOrEmpty();
var someInternalPokey = new SomeInternalPOCOWrapper();
var ctx = (this as IObjectContextAdapter).ObjectContext;
var con = new SqlConnection("xxxxx");
{
con.Open();
DbCommand cmd = con.CreateCommand();
cmd.CommandText = "exec dbo.usp_XXX #xxxx";
cmd.Parameters.Add(new SqlParameter("xxxx", xxx));
using (var rdr = cmd.ExecuteReader())
{
// -- RESULT SET #1
someInternalPokey.Prop1 = ctx.Translate<InternalPoco1>(rdr);
// -- RESULT SET #2
rdr.NextResult();
someInternalPokey.Prop2 = ctx.Translate<InternalPoco2>(rdr);
// -- RESULT SET #3
rdr.NextResult();
someInternalPokey.Prop3 = ctx.Translate<InternalPoco3>(rdr);
// RESULT SET #4
rdr.NextResult();
someInternalPokey.Prop4 = ctx.Translate<InternalPoco4>(rdr);
}
con.Close();
}
return someInternalPokey;
}
Essentially, it's basically like classic ADO.NET. You read the DbReader, advance to the next result set, etc.
But at least we have the Translate method which seemingly does a left-to-right between the result set fields and the supplied entity.
Note the method is internal.
My Repository calls this method, then hydrates the DTO into my domain objects.
I'm not 100% happy with it for 3 reasons:
We have to cast the DbContext as IObjectContextAdapter. The method Translate should be on DbContext<T> class IMO.
We have to use classic ADO.NET Objects. Why? Stored Procedures are a must have for any ORM. My main gripe with EF is the lack of the stored procedure support and this seems to not have been rectified with EF CTP5.
You have to open a new SqlConnection. Why can't it use the same connection as the one opened by the EF Context?
Hope this both helps someone and sends out a message to the EF team. We need multiple result support for SPROCS off the shelf. You can map a stored proc to a complex type, so why can't we map a stored proc to multiple complex types?