I'm using jqGrid and I have a problem getting Dynamic Linq to work. I used NuGet to install Dynamic and added "using System.Linq.Dynamic;".
Using VS 2010 Pro, MVC 3.0
This works:
var s = context.testdata;
var c = s.Count();
c shows 5136 items.
But I cannot get the dynamic approach to work:
var s = context.testdata.OrderBy("id asc");
I get this error message:
'id' could not be resolved in the current scope or context.
Make sure that all referenced variables are in scope,
that required schemas are loaded, and that namespaces are referenced correctly.
This however does work:
var s = (from ss in context.testdata
orderby ss.id
select ss).ToList();
var c = s.Count();
Again I get all 5136 items.
I've got the code from here:
http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
and here:
http://www.timdavis.com.au/code/jquery-grid-with-asp-net-mvc/
Any idea what I am doing wrong?
OK, found the solution here:
Strange Exception thrown using Dynamic Linq Entity Framework Query
This works:
var s = context.testdata.OrderBy("it.id asc");
Related
Im using playwright with C# and a trying to do the following:
I have two elements with the same locator.
I want to be able to locate one of them by position, i.e 1st or 2nd found.
when do the following:
var nameField = page.Locator("div[data-key='Name']");
await nameField.FillAsync("");
I get the error:
Microsoft.Playwright.PlaywrightException : Error: strict mode violation: "div[data-ph-key='Name']" resolved to 2 elements:
Ive tried the following based on the playwright documentation:
var nameField = page.Locator("div[data-ph-key='Name'] >> nth=0");
this results in the element resolved to 2 elements error:
also tried this
var nameField = page.Locator("div[data-key='Name']");
await nameField.First.FillAsync("");
which returns the same error
How can do a simple select the nth element found and interact with it?
Is there something similar to selenium's IWebelements where I would put all the matching elements in a collection and interact with the desired one based on its index position?
Okay, so this works:
var nameField = page.Locator("div[data-key='Name']")
await nameField.Nth(0).FillAsync("");
I'm running a forum with Umbraco 7, and I wish to update a property on a specific member by hes Id.
This is what I tried:
var authorId = Model.Content.GetPropertyValue<int>("postAuthor", 0);
var author = Members.GetById(authorId);
umbraco.cms.businesslogic.member.Member member = umbraco.cms.businesslogic.member.Member.GetMemberFromEmail(author.GetPropertyValue("email").ToString());
member.getProperty("postCounter").Value = Convert.ToInt32(member.getProperty("postCounter")) + 1;
member.Save();
But this dont work and the line below throws this error:
umbraco.cms.businesslogic.member.Member member = umbraco.cms.businesslogic.member.Member.GetMemberFromEmail(author.GetPropertyValue("email").ToString());
It says: Warning: umbraco.cms.businesslogic.member.Member is obsolete: "Use the MemberService and the Umbraco.Core.Models.Member models instead"
Can someone help me solve this?
var memberService = ApplicationContext.Current.Services.MemberService
var member = memberService.GetById(authorId)
member.SetValue("postCounter", newValue);
memberService.Save(member);
Never, ever do this though!!
You need to store counts like this that update really frequently in your own separate table as each time you save a piece of content (and yes, the member object is basically a piece of content as well) you will save a new version in the versions table. All of your custom properties will also be saved again with the new version. Also this is a fairly database-intense operation which is completely unnecessary, just have a table with two columns: the memberId and the count and you're done and it's all very lean and performant.
If you are in razor script you want to do something like:
var authorId = Model.Content.GetPropertyValue<int>("postAuthor", 0);
var ms = ApplicationContext.Current.Services.MemberService;
var member = ms.GetById(authorId);
member.SetValue("postCounter",member.GetValue("postCounter"));
But as sebastian says you probably want to do it differently for performance
I am working on a first Slickgrid MVC application where the column definition and format is to be stored in a database. I can retrieve the list of columns quite happily and populate them until I ran into the issue with formatting of dates. No problem - for each date (or time) column I can store a formatter name in the database so this can be retrieved as well. I'm using the following code which works ok:
CLOP_ViewColumnsDataContext columnDB = new CLOP_ViewColumnsDataContext();
var results = from u in columnDB.CLOP_VIEW_COLUMNs
select u;
List<dynColumns> newColumns = new List<dynColumns>();
foreach(CLOP_VIEW_COLUMN column in results)
{
newColumns.Add(new dynColumns
{
id = column.COLUMN_NUMBER.ToString(),
name = column.HEADING.Trim(),
field = column.VIEW_FIELD.Trim(),
width = column.WIDTH,
formatter = column.FORMATTER.Trim()
});
}
var gridColumns = new JavaScriptSerializer().Serialize(newColumns);
This is all fine apart from the fomatter. An example of the variable gridColumns is:
[{"id":"1","name":"Date","field":"SCHEDULED_DATE","width":100,"formatter":"Slick.Formatters.Date"},{"id":"2","name":"Carrier","field":"CARRIER","width":50,"formatter":null}]
Which doesn't look too bad however the application the fails with the error Microsoft JScript runtime error: Function expected in the slick.grid.js script
Any help much appreciated - even if there is a better way of doing this!
You are assigning a string to the formatter property, wich is expected to be function.
Try:
window["Slick"]["Formatters"]["Date"];
But i really think you should reconsider doing it this way and instead store your values in the db and define your columns through code.
It will be easier to maintain and is less error prone.
What if you decide to use custom editors and formatters, which you later rename?
Then your code will break or you'll have to rename all entries in the db as well as in code.
I've created my first custom Umbraco 5.1 solution. At this point I have a content item ("homepage") with a custom template which has a custom partial macro on it. Now how do I load an entity using the Umbraco helper? I've tried adding several HiveId constructions using a Uri, however I keep getting the same error:
Parameter 'other' must be of type Guid to convert to a Guid CLR type, but it is 'Uri', with value: xxx
Macro partial:
#inherits PartialViewMacroPage
#using Umbraco.Cms.Web
#using Umbraco.Cms.Web.Macros
#using Umbraco.Framework
#{
//All these fail with the same error message...
//Based on name:
var p = Umbraco.GetContentById(
new HiveId(
new Uri("content://Homepage")));
//Based on path
var p = Umbraco.GetContentById(
new HiveId(
new Uri("content://p__nhibernate/v__guid/5a4abe489a2e47858bd2a0580180b683")));
//With custom Hive provider (I've added this using a custom tree/section and products show up, so the hive provider works)
var p = Umbraco.GetContentById(
new HiveId(
new Uri("custom://products/1")));
}
Why are you creating a Uri?
The HiveId accepts a string parameter which you can use instead. So does Umbraco.GetContentById(string id)
I am Umbraco 5 certified and we never used the Uri overload of the HiveId constructor.
var p = Umbraco.GetContentById("yourStringHiveIdHere"); //(string overload) or
var p = Umbraco.GetContentById(new HiveId("yourSringHiveIdHere")); // (HiveId overload)
Also where are you getting your HiveId from?
I need to modify the T4 template POCO.tt to retrieve the database schema from the EDMX file. I can see the schema stored in an EntitySet tag in the XML. However I cannot find the schema anywhere when using an EntitySet object.
Anyone know where I would find the database schema?
Thanks
UPDATE
I wrote up my findings on this in a blog post:
http://www.ninjanye.co.uk/2011/06/getting-schema-information-from-edmx.html
http://jnye.co/Posts/3/getting-schema-information-from-an-edmx-file-with-poco
I came across this same problem myself.
First you need to retrieve the EntityContainer from the Storage Model Content (edmx:StorageModels) section of the edmx file
At the top of the tt template (after the MetadataLoader is instantiated and the inputFile is declared) add the following code to get the Storage Model Content EntityContainer
StoreItemCollection sic;
loader.TryCreateStoreItemCollection(inputFile, out sic);
EntityContainer sicEntityContainer = sic.GetItems<EntityContainer>().First();
Then from within the foreach (var entity in ItemCollection.GetItems...) loop you can get the current schema with the following
EntitySet eset = sicEntityContainer.GetEntitySetByName(code.Escape(entity), true);
string schemaName = eset.MetadataProperties["Schema"].Value.ToString();
Note: You may have to repeat the get schema code for ComplexType properties lower down in the tt template
I think I misunderstood your question the first time. Have you examined the edmx schema for any clues?
According to this link: http://msdn.microsoft.com/en-us/library/cc982042.aspx
The schema for applications that
target the .NET Framework version 4 is
defined in the
Microsoft.Data.Entity.Design.Edmx_2.xsd
file. The schema for applications that
target the .NET Framework version 3.5
SP1 is defined in the
Microsoft.Data.Entity.Design.Edmx_1.xsd
file.
Those are in %VS100COMNTOOLS%\..\..\Xml\Schemas\ for VS 2010, and %VS90COMNTOOLS%\..\..\Xml\Schemas\ (the 3.5 only) for VS 2008
I'm working with EF6 and wanted to add a summary comment to the classes being generated by the t4 template. After hacking around for a while, I managed to do it by loading the EDMX file and using XPath to find what I needed.
var xmlContent = XDocument.Load(textTransform.Host.ResolvePath(inputFile));
var edmxNavigator = xmlContent.CreateNavigator();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(edmxNavigator.NameTable);
nsMgr.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx");
nsMgr.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator");
nsMgr.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/11/edm/ssdl");
nsMgr.AddNamespace("cs", "http://schemas.microsoft.com/ado/2009/11/mapping/cs");
//This is the loop that came with the default template
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
{
fileManager.StartNewFile(entity.Name + ".cs");
BeginNamespace(code);
var mappingAttribute = edmxNavigator.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:Mappings/cs:Mapping/cs:EntityContainerMapping/cs:EntitySetMapping/cs:EntityTypeMapping[#TypeName=\"" + entity.FullName + "\"]/cs:MappingFragment/#StoreEntitySet", nsMgr);
var entitySet = edmxNavigator.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityContainer/ssdl:EntitySet[#Name=\"" + mappingAttribute.Value + "\"]", nsMgr);
var actualTableName = (entitySet.SelectSingleNode("#Table") ?? entitySet.SelectSingleNode("#Name")).Value;
var actualSchemaName = (entitySet.SelectSingleNode("#Schema", nsMgr) ?? entitySet.SelectSingleNode("#store:Schema", nsMgr)).Value;
#>
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
/// <summary>
/// Database Object: <#=actualSchemaName#>.<#=actualTableName#>
/// </summary>
<#=codeStringGenerator.EntityClassOpening(entity)#>
See http://brewdawg.github.io/Tiraggo.Edmx/ you can install it via NuGet within Visual Studio and it serves up ALL of the metadata from your EDMX files that Microsoft hides from you, very simple, works great. You want access to all that low level storage information like your property SQL types, the schema, it's all there. You can even use the Sample Windows.Forms app in the github repo to set a breakpoint and examine the data.
Facing this issue a few weeks ago. As a result create Xslt transformation of EDMX to XSD. https://wash-inside-out.blogspot.com/2022/12/edmx-file-to-xsd-with-xslt.html