Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, July 5, 2013 4:05 PM
Hi: I am trying to store and retreive a xaml resource file in SQL Server using Entity Framework. I have a simple test app to do this in C# and Xaml and a simple database with a StationObjectName field in type nchar(10), a XmlResourceFile field in type xml, and a TestString field in nchar(20). I get the same error if I try saving a string in TestString or a xaml file in XmlResourceFile.
The error is: Unable to update the Entity XmlTestTable because it has a Defining Query and no <Insert Function> element exists in the <ModificationFunctionMappingElement> to support the current operation.
The part of the code giving this error is:
//saves the xml to the database MyTestDB
private void btnSaveToDB_Click(object sender, RoutedEventArgs e)
{
try
{
//this creates a variable and gets the new equipment type information
//from the station object in StationObjectCreationUtility
//it then sends the information to the data base
var newEquipType = new XmlTestTable();
//save the new station objects name from the text box
newEquipType.StationObjectName = txtbxNewName.Text;
//then save the original xml file to the XmlResourceFile field
newEquipType.XmlResourceFile = docOriginal.ToString();
//add test to TestString to checkout the add method to the database
String test = "This is a test.";
newEquipType.TestString = test;
context.XmlTestTables.AddObject(newEquipType);
//context.AddToXmlTestTables(newEquipType);
context.SaveChanges();
}
Mike Gallinger C.Tech. Cutting Edge Computing Software Developer
All replies (2)
Friday, July 5, 2013 9:36 PM âś…Answered | 1 vote
Hello Mike,
Make sure that your XmlTestTable has a primary key. If it doesn't an "insert" query does not get generated in EF to my understanding.
Thank you,
Nick Metnik
Please mark my response as helpful if it has helped you in any way or as the answer if it is a valid solution.
Blog
LinkedIn
Saturday, July 6, 2013 2:24 AM
Have you tried using the SQL statement to insert and see whether it works? If it doesn't then there nothing to do with your code.
http://www.aspdotnet-suresh.com/2012/12/aspnet-send-xml-file-as-parameter-to.html
chanmm
chanmm