c#-4.0

How to serialize class that derives from class decorated with DataContract(IsReference=true)?

筅森魡賤 提交于 2020-01-04 05:13:52
问题 I have class A that derives from System.Data.Objects.DataClasses.EntityObject . When I try to serialize using var a = new A(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(a.GetType()); serializer.WriteObject(Response.OutputStream, a); I get error TestController+A._Id' is not marked with OptionalFieldAttribute, thus indicating that it must be serialized. However, 'TestController+A' derives from a class marked with DataContractAttribute and an IsReference setting of

Getting property value based on its column attribute value

不羁的心 提交于 2020-01-04 05:11:27
问题 List<MyModel1> myModel1 = new List<MyModel1>(); MyUserModel myUserModel = new MyUserModel(); List<MyModel2> myModel2 = new List<MyModel1>(); myModel1 = m_Service1.GetMyModelFields(); myUserModel = m_Service2.GetMyUserDetails(); myModel2 = (from myModel1Field in myModel1 select new MyModel2 { FieldCaption = myModel1Field.FieldAlias, FieldValue = "" }).ToList<MyModel2>(); myModel1Field.FieldAlias text will be same as value of one of the Column attribute of one of the property in myUserModel. So

How to run MVC3 or newer application in Mono

久未见 提交于 2020-01-04 04:32:08
问题 Default ASP .NET MVC 3 application is created using in Microsoft Web Developer Express 2010 Application is published to file system and copied to Debian server where mono 2.10.8 , Apache and mod_mono are installed. Trying to run application causes error: Server Error in '/mvc3test' Application -------------------------------------------------------------------------------- Could not load type 'System.Web.WebPages.Razor.RazorBuildProvider' from assembly 'System.Web.WebPages.Razor, Version=1.0

Using Effort (EF Testing Tool) with Computed Column

一个人想着一个人 提交于 2020-01-04 04:15:11
问题 I have a number of integration tests which access the DB directly - create test prerequisite objects - performs the tests and then cleans up afterwards - however I wonted to try out the same approach in-memory. I have just used Effort in my project and it works very easily. However I've hit a problem that I have been trying - but unable to solve. One of the tables that I need filled up with dummy data - as a test prerequisite - contains a computed column (nvarchar, not null). For the scope of

How to view the procedural code for any xaml file

对着背影说爱祢 提交于 2020-01-04 04:09:07
问题 I'm working in Visual Studio 2012 with xaml to create an application. When I make a new solution and WPF project and look at the xaml in the application file, I see xmlns , a startupuri , and a tag for application.resources . When I want to see the code-behind that these tags are creating, I have only the .cs file with maybe a few things in it and the mysterious InitializeComponent() that performs all of the parsing. Here's an example of what it looks like: public partial class MainWindow :

Update DbSet.Local after row deletion in the database

南笙酒味 提交于 2020-01-04 04:02:16
问题 I have a DbSet associated to a DbContext (with Entity Framework 4.3). The DbSet is initially loaded with all the entities of a given table X The problem is that I'm not able to Reload the DbSet to get a frech list of the table X after the deletion of one or several rows of that table (deletion done by another DbContext in another application). Here is the line I'm using to reload all the entities of my table: ((IObjectContextAdapter) context).ObjectContext.Refresh(RefreshMode.ClientWins, col)

Update DbSet.Local after row deletion in the database

雨燕双飞 提交于 2020-01-04 04:02:10
问题 I have a DbSet associated to a DbContext (with Entity Framework 4.3). The DbSet is initially loaded with all the entities of a given table X The problem is that I'm not able to Reload the DbSet to get a frech list of the table X after the deletion of one or several rows of that table (deletion done by another DbContext in another application). Here is the line I'm using to reload all the entities of my table: ((IObjectContextAdapter) context).ObjectContext.Refresh(RefreshMode.ClientWins, col)

How to override List.Add method?

折月煮酒 提交于 2020-01-04 02:55:31
问题 Currently I have a error logging class like so: public class Log { public enum LogTypes { Info = 1, Error = 2, Warning = 3 } public string Message { get; set; } public LogTypes LogType { get; set; } public Log(string Message, LogTypes LogType) { this.Message = Message; this.LogType = LogType; } I have this initialiser for a new list: List<Log> LogList = new List<Log>(); How can I use LogList.Add(Message, LogType) instead of LogList.Add(new Log(Message, LogType)); ? I know it is a minor change

Accessing dynamic property in F#

与世无争的帅哥 提交于 2020-01-03 18:45:27
问题 I was trying to access dynamic property in Nancy. In Nancy if pass parameter in query it comes as dynamic property. How can I access that. There are many discussion / question about this but every where, first it is of creating dynamic and then consuming it. How can I consume what is already created? Here are two code snippet public class ParameterModule : NancyModule { public ParameterModule():base("/{about}") { this.Get["/"] = (parameters) => "Hello About" + parameters.about; } } and for F#

Late Binding Magic under VB.NET converted to C#

こ雲淡風輕ζ 提交于 2020-01-03 17:43:11
问题 I should convert some code from VB to C#. Given following lines of VB work (I think only because option is not set to strict): Dim someProp As SomeType Try someProp = CType(SomeInstance, Object).SomeProp ' ... Due to late binding, this code is possible under VB. Of course, following won't work under C#: SomeType someProp; try { someProp = ((object)SomeInstance).SomeProp; // ... How could I formulate something similar under C#? Thx for any tipps sl3dg3 回答1: If you're using C# 4.0: SomeType