How to reload changes using Entity Framework POCO?
I have my WPF app using EF on loading, save etc. my problem is if someone make changes on SQL table directly and if my app is open, I am not able to see those changes. I know that EF caches the table and i have force to reload or refresh. But how this
can be done automaticly. I always thought that therefor we have the INotifyPropertyChanged implementation. Does it not serve for this purpose together with Observeable objects?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
Nope.
inpc is property in viewmodel to view notification.
There is no automatic thing there in EF which says a record has changed. EF is based on ado and there's no push notification mechanism.
I have several approaches to the issue.
1)
Re-read everything when the user decides to. That's that refresh button in my sample.
2)
Add trigger to table which writes away when a record has changed the id, type of change and timestamp.
I then can read changes to a table since a given time ( when the data was last read eg ) and do stuff.
3)
Adds push notifications to the client on changing records. This involves tracking who has what data and it's quite involved.
Bear in mind that sample of mine is step 1.
This sort of thing is several steps down the line from something which just does basic crud in a datagrid.
Hope that helps.
Recent Technet articles: Property List Editing;
Dynamic XAML
Similar Messages
-
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] -
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");
samEEMy 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 -
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 -
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 -
Hi, everyone!
INTRO: I'm new to Lightroom. I've gone through a few books and lots of tutorial courses on lynda and youtube, so I feel quite comfortable with LR 5's import process. This post and question is a pre-import/organizational issue.
I have more than 30,000 old, digitized (scanned) photos dating back to the 1950s. Obviously, most of were taken with old, analog cameras. These are now organized into folders by date.
GOAL: I want to import these photos into LR and be able to find them by metadata dates (Capture Date & Time).
PROBLEM: Obviously, old scanned (or even more recent manipulated) photos often don't have the correct EXIF creation date info. Even worse, many (or most) of these old images don't even have an EXIF date field!
WHAT I'VE LEARNED: Using exiv2 filename or evix2 -pt filename immediately shows whether there is or is not date info for the photo. If there isn't, exiv2 -pt filename shows nothing. If there is an EXIF date field, it will be shown.
For all these images with no date field, if I import them into Lightroom, there of course is no date info that shows up in the Metadata panel (under Default or EXIF), nor can you change the date (because the field isn't even there).
If exiv2 -pt filename DOES show the Exif.Image.DateTime field, then in Lightroom, you will see the Capture Time and Capture Date fields, and you will see an icon to the right of those dates that allows you to change that date.
If exiv2 -pt filename DOES NOT show this Exif.Image.DateTime field, you can ADD this field by using the command line:
exiv2 -M"set Exif.Image.DateTime Ascii 1965:01:25 15:45:00" filename (or whatever your date/time is).
Now if you import this image into LR, you will find the Capture Time and Capture Date fields under the Metadata > Default panel...AND you can edit them if needed. That is, the above exiv2 -M command added the EXIF date field that LR needs in order to search by date.
WHAT'S MY POINT, AND WHAT'S MY QUESTION? I have no problem using exiv2 to add/change an EXIF creation DateTime field one folder at a time prior to importing them into LR. This will enable me to search on those date fields**.
My question is this: Is there an easier method?
Surely there must be tens (hundreds?) of thousands of "older" photographers like myself who have troves of old photos that have incorrect EXIF creation date fields, or missing the date field entirely (in which case, as I stated above, cannot be added/edited using LR, PS, FileMultiTool, Graphic Converter, etc.).
I realize that I could look at images based on the folder names or file names, or I could enter dates into tags, but such methods of finding images are not nearly as convenient as using Metadata. Therefore, if I know that an image was taken in June 1962, then I'd like the EXIF metadata to have this info so that I can search on it. To have no EXIF date field or to have a date field that is incorrect is useless.
I'D LOVE YOUR COMMENTS! If there is an easier or better way, I'd love for you to help! There are so many experienced photographers on this forum, and more than likely many of them have old photos with incorrect or missing EXIF date fields that they've brought into LR.
THANKS! I'll really appreciate any and all help you can offer.
David
** there are other EXIF date fields that can be changed using exiv2: Exif.Photo.DateTimeOriginal, Exif.Photo.DateTimeDigitized, etc. But the principal date that LR uses to search for files is the one described above.
P.S. I've also tried jhead -ds1965:01:25 filename (or whatever your date is) to change the date. This works ONLY IF there is already an EXIF date field present. If not, jhead will report an error and not create one. exiv2 -M will create the field.John,
Thanks very much for your help! I had tried the plugin, exiv2, exiftool, and LR's Metadata menu option only on a single photo.
You are 100% correct about LR's menu option assigning different times! Thank you for pointing this out.
When I set the date and time for about 10 photos, LR's menu option assigned (seemingly random!) times to all of them. Why would LR do this? I can perhaps see offsetting each photo by 1 second (00, 01, 02,...), but simply assigning random times makes no sense at all. At least in the tests I just did, LR didn't shift the time by the same amount, but assigned totally (random?) times to every photo.
Another problem that I found with the LR menu item is that it failed to change the date/time at all for several of the images I selected! The Capture Time To Exif plugin, exiv2, and exiftool had no problem at all with the same photos.
I also looked at the ExifMeta by Rob Cole that you mentioned. It looks very powerful (and is free), but much more complex than what I need at this point.
Therefore, I purchased the Capture Time To Exif plugin, and it works great on multiple photos.
I now have good methods to change the date for multiple images:
1. Prior to import: exiv2 or exiftool
2. After import: John's Capture Time To Exif plugin
Thank you again for your help!
This brings me one step closer to importing my photos in a logical method.
David -
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. -
How to add DFF using OA Framework Extensions
Dear Members,
I am very new to OA Framework. I have a requirement where i need to add a DFF to a standard Oracle form in iExpense.
How do we achieve this. Can we do this using forms personalization?
Following are the details of the OAFramework version in our company:
Product/Component Version
OA Framework - 11.5.10 4RUP
Oracle Applications Extension - 9.0.3.8.13 - build 1541
Business Components - 9.0.3.13.87
UIX (Cabo) - 2_2_24
BiBeans Runtime - 3.1.0.70 nondebug BI Beans OAF 11.5.10 Production Release
MDS - 9.0.5.4.89_555
XML - Oracle XDK Java 9.0.4.0.0 Production
AOL/J - Applications Object Library, Core Java Roll Up Patch J
Servlet - 2.2
Java - 1.4.2
JDBC Driver - 9.2.0.6.0
Database - Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
Operating System - AIX 5.3
Browser - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; .NET CLR 2.0.50727; InfoPath.1)
Your Comments are greatly appreciated.
Thanks
SandeepSandeep,
First of all check the Table on which you are having your DFF. If its at the same level as of the Page (I mean the Page VO is on the same table) then there is a high likelihood that ORacle would have provided the DFF and you just need to set the rendered property to true. In Personalize Page you need to provide a Segment List which is a concatenated list of AttributeCategory and allowed Segments for the DFF.
Dev guide is a good place to look for details.
Regards
Sumit -
How to easily change used namespaces
Hi All
Is there an esay way or what is the best practice to change all the used namespaces (for all models, controllers and so on) in a dynpro project, e.g. from com.<companyname>.<projectID> to com.<companyname>.pct.<projectID>?
ThanksHello Reike,
Select the webDynpro Component and right click the same to choose "Rename" from the context menu. Specify the new package that you want.
Balakrishnan -
How to view changes using SVN plugin for SQL developer
Hi,
We recently moved to SVN. I have checked out the PL/SQL code from the SVN server to my local C Drive. But after I have made changes to couple of PL/SQL files, I am not able to figure out how to see my changes and compare with the checked out version (for example, like we have CVS diff option). I searched through the options but could not find any suitable option.
Can someone point or help how to do this ?
I want to check my changes before committing to the main trunk
Thanks,
RaviIn your window where you edit queries, right above the window, below the tab, next to a tab that says "SQL Worksheet" there is a tab that says "History"; click that, see diff(s). See here: http://duncandavies.files.wordpress.com/2009/02/sqldeveloperhistorytab.jpg?w=460&h=257
-
How to totaly change used mac to my id only ?
I thought I have everything in my mane and ID but I am trying to due an update and the previous owners ID comes up , then asking for her ID not mine. I have been using it for over 2 months with no problem until now. Please someone help.
That is because the OS was obtained at the app store and it is not transferable - it is tied to the apple ID of the original purchaser forever. You will not be able to update or reinstall (because it is not transferable). The seller is obliged to remove the OS and reinstall the original OS version.
So, you will need to figure out what the version is that you are running and what version the Mac came with. If you cannot contact the seller, call Apple, give them your serial number, and ask them to send you replacement installation disks (if the Mac came with Snow Leopard or earlier). If it was Lion or later, a different approach is indicated. Can you post the model/year/model identifier of your Mac please. -
Hello,
I use Entity Framework code first approach.
My project is working fine with SQL Server. But, I want to access Oracle too. I want to switch SQL Server and Oracle in run time.
I am able to access Oracle using "Oracle.ManagedDataAccess.EntityFramework.dl" in a new project.
But, Is this possible to access SQL Server and Oracle in the same project.
Thanks,
MuruganThis should be possible with a Code-First workflow. In Code-First the database mapping layer is generated at runtime.
David
David http://blogs.msdn.com/b/dbrowne/
Maybe you are looking for
-
OAS 4.0.8.1/Redhat 6.2? WRKSF problem
Hi, I've installed OAS 4.0.8.1 on Redhat 6.2 but when I start the processes up the WRKSF goes down after a few seconds, I've seen a previous posting on this subject had a workaround proposed by Dennis Irwin which seemed to work for many people, unfor
-
I am trying to set up rules in iCloud and gmail on my server, does anyone know how?
I am trying to set up rules in iCloud and gmail on my server, does anyone know how?
-
Trying to clone in retouch what is option - click?
I am new to the mac trying to retouch my photos using clone. It keeps telling me to option-click. I have tried clicking on everything and help is no help.
-
Replacement options for VW01/VW10 in ECC 6.0 due to ITS retirement
Due to a planned Internet Transaction Server (ITS) retirement, I am investigating replacement/alternatives to VW01 and VW10 for sales order creation and status. Are there other options in ERP ECC 6.0? Many thanks Jennifer Ellis
-
CAn't open any pdf files after updating my Acrobat. What do I do now?