Is there a Threadsafe Observable collection in .NET 4?

There are two possible approaches. The first would be to inherit from a concurrent collection and add INotifyCollectionChanged functionality, and the second would be to inherit from a collection that implements INotifyCollectionChanged and add concurrency support. I think it is far easier and safer to add INotifyCollectionChanged support to a concurrent collection. My suggestion is … Read more

How to send data in jquery.post to mvc controller which use ViewModel as parameter?

$.post(“Yourcontroller/YourAction”, { FirstName : $(“#txtFirstName”).val(), LastName : $(“#txtLastName”) } ,function(data){ //do whatever with the response }); Your ViewModel Property names and Parameter we are passing should be same. Ie : Your view model should have 2 properties called FirstName and LastName like his public class PersonViewModel { public string FirstName { set;get;} public string LastName … Read more

mapping multiple tables to a single entity class in entity framework

You can use Entity Splitting to achieve this if you have the same primary key in both tables. modelBuilder.Entity<TestResult>() .Map(m => { m.Properties(t => new { t.Name, t.Text, t.Units /*other props*/ }); m.ToTable(“Result”); }) .Map(m => { m.Properties(t => new { t.Status, t.Analysis /*other props*/}); m.ToTable(“Test”); }); Here’s a useful article

Best ORM to use with C# 4.0 [closed]

UPDATE 2016 Six years later things are VERY different. NHibernate is all but abandoned, other alternatives were abandoned (eg Subsonic), Entity Framework is perhaps the most common full-featured ORM, and people have been moving to micro ORMs like Dapper for years, to map from queries to objects with a minimum of overhead. The application scenarios … Read more

using ILMerge with .NET 4 libraries

There was a very recent release to solve x64 problems. Get in touch with Mike Barnett directly if you still have problems (mbarnett at microsoft dot com) Addendum. There’s something very, very wrong about your /lib:”C:\Windows\Microsoft.NET\Framework64\v4.0.30319″ option. This has been getting lots of programmers in trouble lately, after .NET 4.5 was released. That directory is … Read more

How to get current working directory path c#?

You can use static Directory class – however current directory is distinct from the original directory, which is the one from which the process was started. System.IO.Directory.GetCurrentDirectory(); So you can use the following to get the directory path of the application executable: System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

Using DataContractSerializer to serialize, but can’t deserialize back

Here is how I’ve always done it: public static string Serialize(object obj) { using(MemoryStream memoryStream = new MemoryStream()) using(StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); serializer.WriteObject(memoryStream, obj); memoryStream.Position = 0; return reader.ReadToEnd(); } } public static object Deserialize(string xml, Type toType) { using(Stream stream = new MemoryStream()) { byte[] data = … Read more