I have a field in a table defined as xml so in my dbml it's showing up as an xelement. I have an xmlwriter in my class that needs to write it's xml to this field but calling tostring on the writer doesn't work. How do I assign the xmlwriter or it's contents to an xelement? Thanks.
Related
I'm using Spring-Data-ElasticSearch to index a whole object as a document in Elastic. One of the field is a String typed base64 encoding of user upload file.
#Document(indexName = "user_record")
public class UserRecord {
private String base64UserUploadFile;
...
Currently this base64 string is indexed directly into Elastic so not searchable, so I'm wondering what's my options here if I want to be able to search the actual content from that file without having to convert this field to be the actual file content string in my class?
You might want to use the mapper-attachments plugin and declare your field with the Attachment field type
#Document(indexName = "user_record")
public class UserRecord {
#FieldType(type = FieldType.Attachment, store = false)
private String base64UserUploadFile;
...
That way the Base64 content will be indexed and searchable. I suggest not to store the content (hence store=false) if you don't want to inflate your index unnecessarily.
im using c# with Entityframework to access to a Oracle database. After update the entities on the model, i'm just adding a new entity do a dbset, then i call dbcontext.SaveChanges(), and a exception is thrown "Input string was not in a correct format."
As Oracle does not have autonumbers, i've changed the "StoreGeneratedPattern" to Identity and the table where i'm tring to add a row have a relation to other table.
i'm missing something too basic?
some ideas?
myentity oNew = new myentity(){...}
ctx.myentity.Add(oNew);
ctx.SaveChanges();
I have a simple WebAPI2 service that uses OData (System.Web.Http.OData, 5.1.0.0). Users can hit /odata/$metadata to get the available entities and properties. I'm looking for a way to extend this metadata with additional information, such as adding a "display name" value to a property.
I found information about "annotations" that sounds like it is what I want, but I cannot find anything explanining how to use this in my scenario or if it is even possible. I was trying to do something like the following:
model.SetAnnotationValue(((IEdmEntityType)m.FindType("My.Thing")).FindProperty("SomeProperty"),
namespaceName:"MyNamespace",
localName: "SomeLocalName",
value: "THINGS");
The type/property names are correct and the call succeeds, but the OData EDMX document does not contain this annotation. Is there some way to expose these annotations or otherwise do what I want?
Update:
Still at it. I've been looking at ODataMediaTypeFormatters as a possible way to handle this. There is an ASP.NET sample project that shows how to add instance annotations to entities. Close, but not exactly what I want, so now I'm trying to find a way to extend whatever generates the metadata document in a similar way.
I figured out a way to do this. The code below adds a custom namespace prefix "myns" and then adds an annotation on a model property:
const string namespaceName = "http://my.org/schema";
var type = "My.Domain.Person";
const string localName = "MyCustomAttribute";
// this registers a "myns" namespace on the model
model.SetNamespacePrefixMappings(new [] { new KeyValuePair<string, string>("myns", namespaceName), });
// set a simple string as the value of the "MyCustomAttribute" annotation on the "RevisionDate" property
var stringType = EdmCoreModel.Instance.GetString(true);
var value = new EdmStringConstant(stringType, "BUTTONS!!!");
m.SetAnnotationValue(((IEdmEntityType) m.FindType(type)).FindProperty("RevisionDate"),
namespaceName, localName, value);
Requesting the OData metadata document should give you something like this:
<edmx:Edmx Version="1.0">
<edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema Namespace="My.Domain">
<EntityType Name="Person">
<Key><PropertyRef Name="PersonId"/></Key>
<Property Name="RevisionDate" Type="Edm.Int32" Nullable="false" myns:MyCustomAttribute="BUTTONS!!!"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
You can set a custom property to any IEdmEntityType, thus also for . Simply modify kenchilada's code as follows:
m.SetAnnotationValue(m.FindType(type), namespaceName, localName, value);
I have a model source (name, url, method)
The program parses the source's url for data. Now I have differen classes for parsing different types of urls: rss, xml, ogdata ...
So I have a common interface
new(url) //Parses the url
getTitle() //Get the title of the data
getPrice() //Get the price
And I have four classes rss, xml, ogdata. These classes are in seperate files. The idea is to add more classes as I discover different types of pages. I want to initiate the right classes for the url.
method=source.method
//NOw I want to create a new class of the name specified in method
parser=Rss.new(source.url)//Instead of this
//Something like
parser=.new(source.url)
You can try using const_get.
Ex:-
Kernel.const_get("YourClassNameHere").new
*Kernel.const_get("YourClassNameHere")* will get you the class. And you can use it to instantiate new instances of the class.
irb(main):081:0> User.name
=> "User"
then
"User".constantize.new(name: 'David')
or
User.name..constantize.new(name: 'David')
I am trying to update a 'Name' DataColumn based on a 'ID' DataColumn in a DataTable.
The 'ID'-'Name' pairs are stored in a Dictionary, which is created using a DataTable extension method as follows:
public static Dictionary<object, object> ToDictionary(this DataTable dataTable, string keyColumn, string valueColumn)
{
Dictionary<object, object> resultDict = new Dictionary<object, object>();
if (dataTable.Columns.Contains(keyColumn) && dataTable.Columns.Contains(valueColumn))
{
foreach (DataRow dr in dataTable.Rows)
if (resultDict.ContainsKey(dr[keyColumn]) == false)
resultDict.Add(dr[keyColumn], dr[valueColumn]);
}
return resultDict;
}
I am using the following LINQ syntax to update the DataColumn:
misUserDetailsDT.AsEnumerable().ToList().ForEach(row => row.SetField("DepartmentName", deptDict[row["DepartmentID"]].ToString()));
Here 'misUserDetailsDT' is the DataTable containing a filled column 'DepartmentID' and an empty column 'DepartmentName'-which I am trying to update.
I have a seperate method which generates the Dictionary as follows:
var deptDict = departmentDT.ToDictionary("DeptID", "DeptName");
where 'departmentDT' is a DataTable containing columns 'DeptID' and 'DeptName'.
Now when I execute the Linq code it give a 'KeyNotFoundException'. I have thoroughly checked that the 'departmentDT' table as well as 'deptDict' have all the keys(departmentIDs) from the 'misUserDetailsDT' table. Actually the 'departmentDT' itself has been generated from all the distinct IDs of 'misUserDetailsDT' table.
I think there is some issue with figuring out the appropriate type of the Dictionary keys. I even tried casting it to Int16, but it didn't work out.
Please help me figure out a solution.
I have figured out the problem. The code works when dictionary values are casted to Int32. Thanks to #TimSchmelter for giving a very useful info. I will be changing the code to make use of foreach loop instead.