Unable to Update .mdf using Entity Framework
I am trying to insert Data in an .mdf file using Entity Framework but there is no data saved in the database. (I am using VS 2013)
Code against the button is
private void BtnSubmit_Click(object sender, RoutedEventArgs e)
Product record = new Product();
record.ProductName = txtProductName.Text;
AzadIndustryEntities1 Db = new AzadIndustryEntities1();
Db.Products.Add(record);
Db.SaveChanges();
MessageBox.Show("Record Inserted");
samEE
My problem is solved. Going to explain it so that it could help others also.
As the default property of .mdf file Copy to Output Directory is
Copy always so when we debug our program a copy of the .mdf file is copied in the
debug folder which is in the bin folder (Select
Show All Files in Solution Explorer to view the bin folder) so, whatever changes we make in database through
code it is saved in the copied .mdf that is in the debug folder. When we
debug our program again the same steps are performed again and the previous database is
overwritten. To prevent such happening the property of .mdf file mentioned above should be set to
Copy if newer so, if there is any change in the model only then the .mdf will be overwritten
samEE
Similar Messages
-
Using Entity Framework with SQL Azure - Reliability
(This is a cross post from http://stackoverflow.com/questions/5860510/using-entity-framework-with-sql-azure-reliability since I have yet to receive any replies there)
I'm writing an application for Windows Azure. I'm using Entity Framework to access SQL Azure. Due to throttling and other mechanisms in SQL Azure, I need to make sure that my code performs retries if an SQL statement has failed. I'm trying to come up with
a solid method to do this.
(In the code below, ObjectSet returns my EFContext.CreateObjectSet())
Let's say I have a function like this:
public Product GetProductFromDB(int productID)
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
Now, this function performs no retries and will fail sooner or later in SQL Azure. A naive workaround would be to do something like this:
public Product GetProductFromDB(int productID)
for (int i = 0; i < 3; i++)
try
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
catch
Of course, this has several drawbacks. I will retry regardless of SQL failure (retry is waste of time if it's a primary key violation for instance), I will retry immediately without any pause and so on.
My next step was to start using the Transient Fault Handling library from Microsoft. It contains RetryPolicy which allows me to separate the retry logic from the actual querying code:
public Product GetProductFromDB(int productID)
var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(5);
var result = _retryPolicy.ExecuteAction(() =>
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault;
return result;
The latest solution above is described as ahttp://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx Best Practices for Handling Transient Conditions in SQL Azure Client
Application (Advanced Usage Patterns section).
While this is a step forward, I still have to remember to use the RetryPolicy class whenever I want to access the database via Entity Framework. In a team of several persons, this is a thing which is easy to miss. Also, the code above is a bit messy in my
opinion.
What I would like is a way to enforce that retries are always used, all the time. The Transient Fault Handling library contains a class called ReliableSQLConnection but I can't find a way to use this with Entity Framework.
Any good suggestions to this issue?Maybe some usefull posts
http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx
http://geekswithblogs.net/iupdateable/archive/2009/11/23/sql-azure-and-entity-framework-sessions-from-pdc-2009.aspx -
Self Reference Model Class - How to populate using Entity Framework
Hi,i have table in SQL Server named Employees as follows:
EmployeeId lastName FirstName reportsTo
1 Davolio Nancy 2
2 Fuller Andrew NULL
3 Leverling Janet 2
4 Peacock Margaret 2
5 Buchanan Steven 2
6 Suyama Michael 5
7 King Robert 5
8 Callahan Laura 2
9 Dodsworth Anne 5
I would like to use Entity Framework to populate my Model Class .My model class looks as follows:
public class Employees
readonly List<Employees> _children = new List<Employees>();
public IList<Employees> Children
get { return _children; }
public string FirstName { get; set; }
public string LastName {get; set;}
I want to use this class in ViewModel to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.
AlmirHello Fred,
unfortunately it does not work, maybe I can be more specific about what I'm trying to get. I'm following Josh Smith's article on CodeProject related to WFP TreeView
Josh Smith article. He has Class named Person with the following structure
public class Person
readonly List<Person> _children = new List<Person>();
public List<Person> Children
get
return _children;
public string Name { get; set; }
The same is populated from Database class using method named GetFamilyTree() which look as follows:
public static Person GetFamilyTree()
// In a real app this method would access a database.
return new Person
Name = "David Weatherbeam",
Children =
new Person
Name="Alberto Weatherbeam",
Children=
new Person
Name="Zena Hairmonger",
Children=
new Person
Name="Sarah Applifunk",
new Person
Name="Jenny van Machoqueen",
Children=
new Person
Name="Nick van Machoqueen",
new Person
Name="Matilda Porcupinicus",
new Person
Name="Bronco van Machoqueen",
new Person
Name="Komrade Winkleford",
Children=
new Person
Name="Maurice Winkleford",
Children=
new Person
Name="Divinity W. Llamafoot",
new Person
Name="Komrade Winkleford, Jr.",
Children=
new Person
Name="Saratoga Z. Crankentoe",
new Person
Name="Excaliber Winkleford",
I'm trying to figure out how should I write
GetFamilyTree() method using Entity Framework in order to connect to my SQL Server database and populate this Person class as it was populated manually in Joshs Example. The table I'm using in SQL Server is described in
my first post named Employees (it's self reference table) -
MVC 4 Using Entity Framework How to save Images in Database
Iam Beginner to
MVC 4 ... I want to Upload Image from my form and save to the SQL Database by Using Entity Framework . I have searched alot but couldnt succeed yet,,http://forums.asp.net/
You should post to the MVC section of above forum first. -
Using Entity Framework with Crystal Master Detail Reporting
My project is a WPF project connected to a SQL Server Compact Edition database. Since Crystal does not support nullable types, I have created classes specifically for the report to consume. This is a simplified version of what I am attempting to do.
For example...
class Band
public string BandName { get; set; }
public string BandCity { get; set; }
public List<BandRecording> RecordingsList { get; set; }
class BandRecording
public string Year { get; set; }
public string Description { get; set; }
In my code behind for this report, I am using Entity Framework to pull the data. Just pulling information for one band...
using (RockEntities re = new RockEntities())
var bandinfo = (from b in re.Band
where b.BandName == "BT"
select new
b.BandName,
b.BandCity,
Recordings = b.Recordings.OrderBy(z => z.Year)
}).FirstOrDefault();
OK, now I start moving to the data to class I have defined...
Band b = new Band();
b.RecordingsList = new List<BandRecording>();
b.BandName = bandinfo.BandName;
b.BandCity = bandinfo.BandCity;
foreach(var Recording in bandinfo.Recordings)
BandRecording br = new BandRecording();
br.Year = Recording.Year;
br.Description = Recording.Description;
b.RecordingsList.Add(br);
Since Crystal Supports IEnumerable, I create a list to hold the main record (although I am only reporting on one band)...
List<Band> lb = new List<Band>();
lb.Add(lb);
ReportDocument rd = new ReportDocument();
rd.Load("BandReport.rpt");
rd.SetDataSource(lb);
I have put the Band info in the Report Header section. This is all working fine. In the details section I would like to put the Band Recording info. I haven't figured out how to do this. I have put the fields in the Details section, but how do I tell the details section to use the inner List<BandRecordings>?
Any help would be greatly appreciated.Only way I can see of doing this would be to place emprty formulas into the section. The populate the formula(s) with the required field;
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Report As New CrystalReport1()
Dim FormulaFields As FormulaFieldDefinitions
Dim FormulaField As FormulaFieldDefinition
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FormulaFields = Report.DataDefinition.FormulaFields
FormulaField = FormulaFields.Item(0)
FormulaField.Text = "[formula text]"
CrystalReportViewer1.ReportSource = Report
End Sub
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports] -
I have started developing a small application in WPF. Since I am completely new to it, to start with I took a microsoft's sample available at
Microsoft Sample Application and following the pattern of the sampke I have been so far successful in creating four different views for their corresponding
master tables. Unfortunately, I have got stuck up as the sample does not contain pattern for creating ViewModel when there is a many-to-many relationship in the database. In my application, I have the following data structure:
1. Table Advocate(advId, Name)
2. Table Party (partyId, Name)
3 Table Case (caseId, CaseNo)
4. Link Table Petitioner (CaseId, PartyId)
5. Link Table Respondent (CaseId, PartyId)
6. Link Table EngagedAdvocate(CaseId, advId)
7. Link Table EngagedSrAdvocate(CaseId, advId)
In the scenario above, I am a bit confused about how to go forward creating the required ViewModel which would render me to have multiple instances of Petitioners, Respondents, Advocates and SrAdvocates.
Please explain details in step by step manner considering that whatever work I have completed so far is a replica of Microsoft's sample referred above. I would also like to mention that I have developed my application
using VB.net. So please provide solution in vb.net.
After getting many-to-many relationship introduced into my application, it would achieve one level above the sample application and I would like to share with the community so that it could be helpful to many aspiring developers seeking help with MVVM.Hi ArunKhatri,
I would suggest you referring to Magnus's article, it provides an example of how you could display and let the user edit many-to-many relational data from the Entity Framework in a dynamic and data-bound DataGrid control in WPF:
http://social.technet.microsoft.com/wiki/contents/articles/20719.wpf-displaying-and-editing-many-to-many-relational-data-in-a-datagrid.aspx
You can learn how to design the ViewModel and the relationship between the entities.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Cannot insert null into a Primary Key Column using Entity Framework
I have to insert data into UserPreferences Table which has a primary key. This I am doing with Oracle Entity Framework Provider.
It is unable to do it though i have set the StoreGeneratedPattern = "Identity". But while saving changes it is saying a null error is being inserted into the primary key.I exported the same package to BIDS and ran it but still unable to get the issue. It is running fine.
Also then same package is running fine in other environments.
Thanks
Thats strange
Are you pointing to same databases itself while executing from server?
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
I unable to update aaps using AppStore - iPhone 4S
I unable to updates apps from AppStore although it shows 3 updates . Pls help , I did every trick I know .
How long did it take for yours to work again? Mine started acting up yesterday and it *****. I can't download apps, and I can't update. My screen doesn't go blank, I can see the updates. But when I click the update button it does NOTHING. Same thing when I try to download stuff! But for some reason, I can download songs! Anyone else have this problem? I tried turning off my phone, restarting it, and even changing the time on my phone. Nothing worked... HELP!
-
I had to create an Apple ID to open a cloud account some time ago. For some time prior to this, I had an account for my iPod. Today I did a sync and was notified of two app updates, but was unable to use my old password and was notified to use my Apple ID. However, when I log in with my Apple ID, the store tells me that I do not own the apps.
How can I get this system to update my iPod apps.
Thanks for any help you can provide.
Certainly not happy with this situation, as Apple expects me to pay for help on this.
Geo321. Don't confuse "Apple ID" with iTunes Account ID. You can have many Apple IDs but only one iTunes account active at a time.
2. If you "changed" your iTunes account ID, you actually have 2 accounts - one under the old name plus the new name.
3. You can't merge the accounts - they remain separate. Apps purcahsed under the old account name will update ONLY WHEN THE PHONE IS SIGNED IN TO THE OLD ACCOUNT NAME and visa versa.
4. Likewise, you can sync only the apps, music, media purchased under the account the phone AND iTunes are signed in to. -
Application update without use the Framework
Hi, all!
Is there a way to implemente a auto-update feature without
using the Adobe AIR Update Framework?
It's because I'm developing into Flash IDE, and seens there
is only a Flex framework available.
I also would like to create my own auto-update framework,
with customized UI and so on.
Thank you.
CaioToOn!Oliver, so if I understand correctly, the Updater class
simply let's you call update() to install a new version based on an
already downloaded AIR file? So the responsibility to check for an
update and download it is still left up to the developer when
building the initial app?
What does the Updater framework provide in addition to this,
and is there a Flash CS3 compatible framework?
Also, what is the purpose of the "version" parameter in the
Updater.update() method, since it has to match the AIR file being
specified anyway?
How should the AIR instance know what version to expect in
the AIR file? Is that also completely up to the developer to
determine?
Thanks. -
Unable to update database using a remote bean call
We have a system, in which one of the EJBs (say, local EJB) in one
system remotely call an ejb (say, remote EJB) on another system. The
problem is the that the remote EJB is unable to database with any
changes when its method was invoked by the local EJB.
We first call a set method which is supposed to update the DB. Then we
call the get method which returns the recently updated value. However
the data is not stored in the DB. The get method seems to retrieve the
data from the cache. There is no exception thrown.
However there is no issue with the remote EJB. If we call the method
locally, it DOES update the database. I dont know if it has to do
anything with the java security policy defined. We use Weblogic 6.1
SP3.
We have a release in another 2 days and any help on this will be
appreciated.We have a system, in which one of the EJBs (say, local EJB) in one
system remotely call an ejb (say, remote EJB) on another system. The
problem is the that the remote EJB is unable to database with any
changes when its method was invoked by the local EJB.
We first call a set method which is supposed to update the DB. Then we
call the get method which returns the recently updated value. However
the data is not stored in the DB. The get method seems to retrieve the
data from the cache. There is no exception thrown.
However there is no issue with the remote EJB. If we call the method
locally, it DOES update the database. I dont know if it has to do
anything with the java security policy defined. We use Weblogic 6.1
SP3.
We have a release in another 2 days and any help on this will be
appreciated. -
Unable to update features using the NWDS Update Manager
I'm updating the NWDS and selecting the features to install from https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/ce/710
It hung midway while downloading:: plugins/com.sap.engine.clientapis_2.0.0.101103141034.jar (9928K of 10560K bytes)
I had to force kill the NWDS and when I restarted it and tried to update the features again, it doesn't try to download the clientapis jar that failed to download before. I don't find this jar in the eclipse\plugins folder either, so why does it skip this jar?
By the way, the features to install automatically listed were as below:
- https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/ce/710
- SAP NetWeaver Developer Studio CE 7.1 SP11 PAT000
- SAP Netweaver Developer Studio Java EE 8.0.110000.101103141042
- SAP Netweaver Developer Studio Development Infrastructure Client 8.0.110000.101103141042
- SAP Netweaver Developer Studio Web Dynpro User Interfaces 8.0.110000.101103141042
- SAP Netweaver Developer Studio Composition Tools 8.0.110000.101103141042
Now it gets repeatedly hung while downloading the jar file
plugins/com.sap.devmanual.doc.user_1.1....818085804.jar everytime I kill and restart and try to update.
The way I update is from the Help menu->Install/Update->Search for new features to install.
In the "Product Configuration" I see the below
- SAP NetWeaver Developer Studio
- E:\Program Files\SAP\IDE\CE\eclipse
- SAP NetWeaver Developer Studio Platform 8.0.110000.101103141042
-Eclipse Platform 3.3.0.v20070612-_19UEkLEzwdF0jSqQ-G
- Eclipse RCP 3.3.0.v20070607-8y8eE8NEbsN3X_fjWS8HPNG
- SAP NetWeaver Developer Studio Composition Environment 7.1.7.1.0.101103141042
Can someone please help understand what is happening and how to get the update manager working, before I get fired from my job for showing no productivity since 2 days? If it is a matter of the mirror being down, can you tell how I can choose a different mirror for a site in the Eclipse Update Manager?
Edited by: convicted on May 6, 2011 1:58 PM
Edited by: convicted on May 6, 2011 2:04 PMIs there any issue with connection to the network(internet) fromt he NWDS?
Usually, NWDS is unable to connect to network due to incorrect Network Connection parameters.
As a workaround, try to locate an existign installation of the NWDS with all the plugins. Ontain those files and save it in your NWDS folder.
Regards,
Sharath -
Unable to Update Wii using Linksys Wireless Router
I am unable to download updates for my Wii, and i cant get into my router to change any settings, i dont know what my password is or anything
Well if you don't know what the password for the wireless is, then its pretty obvious why (if thats what your saying) but if your asking what the password to get into the UI interface for the router is, the default password is admin with no username. There you can switch the password for the wireless, however if there is no password and it just wont connect, move the Wii out in front of your tv to get a better signal.
-
How can I create a database from a sharepoint using entity framework
Hello All,
I want to develop a data base from SharePoint list independently. The column name are based on a SharePoint list eg: Contact-list (will be having 10 columns)
can any one please suggest me an idea on how to do this task? Which Visual Studio template is suitable for this purpose?
I confused with starting with following Visual studio template!!!
Empty SharePoint Project??, Business Data Connectivity Model??, ASP.Net Web application??
Somebody please help me soon....
I am using SharePoint 2010 and Visual Studio 2010Hey,
basically you should start with an empty SharePoint 2010 project where you add an List-EventReceiver. This Receiver should point to the url of the list and handle the ItemAdded-Event. In this method you place the code to create the database, for example
with a SQL-Statement. -
Unable to Update Tasks using PSI
Hi,
I have customized Ms Project Server to update a custom field in the tasks of Project Schedule after checkin of the Project.
The code loops through all tasks and performs QueueUpdate operation to update all changes to Tasks. However, the updates made to the last task of the Project are updated in the system, no changes are saved for rest of the tasks.
Could you please help provide some help in resolving this issue? Any help in this regard would be appreciated.Hi,
I am trying to update Task Custom Fields in project server 2010.But it is throwing error at QueueUpdate Method.
At projectSvc.QueueUpdateProject(jobId, sessionId, myProject, false);
it is giving error:
"ProjectServerError(s) LastError=CustomFieldRowAlreadyExists Instructions: Pass this into PSClientError constructor to access all error information
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at UpdateProjectStoreInformation.ProjectWebSvc.Project.QueueUpdateProject(Guid jobUid, Guid sessionUid, ProjectDataSet dataset, Boolean validateOnly)
at UpdateProjectStoreInformation.ProjectListEventReceiver.ProjectListEventReceiver.ItemAdded(SPItemEventProperties properties)"
Code is written below:
if (taskEfforts != null && taskEfforts.Count > 0)
for (int i = 0; i < myProject.Task.Count; i++)
foreach (string key in
taskEfforts.Keys)
if (myProject.Task[i].TASK_NAME.ToString().ToLower().Equals(key.ToString().ToLower()))
foreach (ProjectDataSet.TaskCustomFieldsRow cfRow in myProject.TaskCustomFields)
if (cfRow.MD_PROP_UID == effortGuid)
Logger.WriteLog("********Updating Efforts**********");
cfRow.NUM_VALUE = Convert.ToDecimal(taskEfforts[key]);
Logger.WriteLog("task name:" + myProject.Task[i].TASK_NAME + " Effort:" + taskEfforts[key]);
break;
//break
bool force = true;
sessionId = Guid.NewGuid();
string sessionDescription = "updated custom
fields";
projectSvc.CheckOutProject(projectGuid, sessionId,
"custom field update checkout");
jobId = Guid.NewGuid();
projectSvc.QueueUpdateProject(jobId, sessionId, myProject,
false);
WaitForJob(jobId);
jobId = Guid.NewGuid();
projectSvc.QueuePublish(jobId, projectGuid, true, siteName);
//create a new job id
jobId = Guid.NewGuid();
//checkin the updated project
projectSvc.QueueCheckInProject(jobId, projectGuid,
force, sessionId, sessionDescription);
//wait for finishing
WaitForJob(jobId);
Thanks
Maybe you are looking for
-
If I have only one product in a catalogue, how can I tell BC to skip the product list view and go straight to the product large view? For example. I would like to be able to click on 'Office Suites' on this page: http://bevisco.businesscatalyst.com/p
-
Pdf files not printing whole page
pdf files printing just part of page. have everything updated on my mac and hp printer. anyone have a solution?
-
Can someone please tell me what's wrong with the following two queries: I'm using Oracle 11.1g select row_number() over (partition by 'test' test order by 'test2' test2 rows between 3 preceding and cu
-
Build numbers for powershell.exe vs. PowerShell version
Hi! I'm looking for information about powershell.exe file build number or version than can allow mi determine installed PowerShell version on remote hosts. Currently I must determine installed version on a lot of servers that I can only get informati
-
Hi everybody, I'm trying to implement user-based data partitioning. I want to store users with the department "IT" in the Database and others in the second Data Store an SAP System. With the following config.xml I achieved this, but the users that we