【c# – 实体框架 – 外键未设置(0 / null)但导航属性不为null】教程文章相关的互联网学习教程文章

c# – 从lambda表达式中排除null或空字符串值【代码】

在我的GetAll函数应用程序中,我有一个名为(CustomerModel)的参数.我用它来对查询进行一些过滤,我使用规范模式来避免使用if-else:public async Task<List<CustomerModel>> GetAllAsync(CustomerModel customer, Order order = Order.Ascending, int pageIndex = 1, int pageSize = int.MaxValue){var skip = (pageIndex - 1) * pageSize;var filter = new CustomerNameSpecification(customer).And(new CustomerNoSpecification(cu...

c# – Web API Post Body Properties null【代码】

我发布了一个来自Angular应用程序的消息,并且每次post主体总是以null形式进入函数.直接在post请求之前登录Angular应用程序的控制台确认该对象确实包含信息,它似乎在整个过程中某处丢失.public class SentMessage {public string MessageFrom { get; set; }public string MessageTo { get; set; }public string Message { get; set; } }// Post a new message [Route("Conversation/AddTo")] [HttpPost] public IHttpActionResult A...

c# – DataContract类中的WCF私有成员引用变为NULL【代码】

我在Web服务层的WCF中存在一个问题. 当我在WCF中实例化我的类的私有成员(_Wagon)(此实例化不为null)时,几秒钟后,它变为null. 我一直在努力诊断问题,但目前还没有结果. 所以我转向你们,帮助我解决这个问题. 谢谢. 因此有我的代码:[DataContract] public class RemoteWagon {private readonly IWagon _Wagon;public RemoteWagon(IWagon Wagon){_Wagon = Wagon; //_Wagon isn't null here}~RemoteWagon(){Trace.WriteLine("Do nothin...

c# – 如何使用VSTO和MEF解析ServiceLocator.Current为null【代码】

在VSTO项目中使用MEF并定义容器如下var catalog = new AggregateCatalog();catalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));catalog.Catalogs.Add(...);container = new CompositionContainer(catalog);container.SatisfyImportsOnce(this);除了代码使用的地方以外,所有人都使用各种库ServiceLocator.Current.GetInstance<MyInterface>()哪个ofcourse抛出NullReferenceException 考虑到ServiceLocator是它自己...

c# – 在nunit测试中,Response.StatusCode为null【代码】

我正在编写单元测试用例.我正在尝试为此方法编写单元测试但显示错误.如何在mvc3框架和rhino mock中对这个方法进行单元测试.public ActionResult UnderConstruction(){Response.StatusCode = (int)HttpStatusCode.TemporaryRedirect;ErrorModel model = new ErrorModel(){ErrorMessage = "This page is still under construction; please check back later.",Title = "Under Construction"};return View("Error", model);}解决方法:...

c# – 从Web App调用时,System.Reflection.Assembly.GetEntryAssembly()为null【代码】

参见英文答案 > GetEntryAssembly for web applications 5个我正在使用目标框架 – 3.5开发Visual Studio 2010中的Web应用程序我正在使用一个DLL(由另一个团队开发),其中我得到以下代码的错误:string strName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;我检查并发现System.Reflection.Assembly.GetEntryAssembly()返回null并且还在msdn上找到并且在从任何非托管代码调...

c# – 要从工厂返回“手动覆盖”值,检查null或布尔开关是否更好?【代码】

假设我们有一个类似的方法public static IThing getTheThing() {return internalThingGetter(); }我们希望出于调试或单元测试的目的,引入轻量级策略来手动覆盖它.private static IThing _thingManualOverride;public static IThing getTheThing() {if (/*some condition*/)return _thingManualOverride;elsereturn internalThingGetter(); }检查_thingManualOverride!= null或引入新的布尔值并检查,例如_shouldOverride是否更好?...

c# – Request.UrlReferrer在Internet Explorer 7,8,9浏览器中返回“null”

对于Internet Explorer 7,8,9浏览器,C#的Request.UrlReferrer返回null.它的原因是什么?它的解决方案是什么? 页面上有一些“点击此处”按钮.单击该按钮,将在新选项卡中打开一个新的URL页面.在打开页面时,我使用Request.UrlReferrer将Page的url存储在数据库中. 对于其他浏览器,如Firefox,Chrome等,它运行正常.但它从未在Internet Explorer上运行过. 请帮帮我.解决方法:在各种情况下,引荐者可以是空的.例如,某些隐私设置(按策略进行...

c# – 即使Datasource为null,Gridview也会显示控件(标签,按钮,文本字段)【代码】

即使我的表列使用gridview为空,如何显示我的控件?我所知道的是ShowHeaderWhenEmpty =“true”解决方法:如果gridview的数据源为null,则可以创建临时数据表并将其指定为gridview的数据源.if (GridView1.DataSource == null){DataTable dt = new DataTable();dt.Columns.Add("Name");DataRow dr = dt.NewRow();dr[0] = "";dt.Rows.Add(dr);GridView1.DataSource=dt;GridView1.DataBind();}

c# – WebAPI传递的post参数为null【代码】

我正在使用WebAPI 2进行测试,我创建了以下控制器方法.// POST api/values public string Post([FromBody] string value) {string returnValue = "Return: " + value ;return returnValue; }当我用fiddler发布以下消息时,方法参数保持返回null.POST http://localhost:50814/api/Values/ HTTP/1.1 Host: localhost:50814 Content-Type: application/json Content-Length: 14{value: "New"}我已经尽可能地简化了我的代码,但它仍然保持...

c# – Xamarin.Forms中的Application.Current Null异常【代码】

在Xamarin.Forms应用程序中,我使用Application.Current.Properties来保存设置.当我的LoginPage加载时,我想看看是否存在设置,但我得到一个异常,说Application.Current是Null.这是(已清理的)代码,它位于LoginPage中:private bool AuthTokenExists(){// The following line throws the exceptionif (Application.Current.Properties.ContainsKey("First") && Application.Current.Properties.ContainsKey("Second")){if (Application...

c# – 为什么Process.Start(string)为WMV文件返回null【代码】

所以我有一个WMV视频文件:var fileName = @"C:\MyFolder\MyVideo.WMV"我正在启动视频并使用代码获取我的Process ID:var process = Process.Start(fileName); if (process != null) {processId = process.Id; }虽然我的视频文件启动,但进程始终为null. 从Process.Start(string) MSDN我可以看到:Return Value Type: System.Diagnostics.Process A new Process that isassociated with the process resource, or null if no proces...

将ASP.NET Web API 2中值类型(C#)的.MinValue序列化为null【代码】

我想将ASP.NET Web API 2中值类型(C#)的.MinValue序列化为传递给客户端时为null.当客户端发送一个null值时,我希望在服务器上获取值类型的.MinValue. 我正在使用Json.Net进行Json序列化和反序列化.此外,我需要相同的URI参数和formdata.我需要以下类型:short,int,long,float,double,decimal,DateTime 我试过的事情: >一种解决方案是使用可空类型.但是在服务器上我更喜欢使用不可为空的类型,因为业务逻辑层正在处理值类型,而在数据访...

c# – 从ManagementObjectCollection中的所有对象获取所有非null属性【代码】

我正在尝试简化这两个foreach循环,但我似乎无法得到它.它使用管理库来获取有关操作系统的信息,大约有30个不同的项目,但我只想要一个.此刻我正在滚动它们并在弹出时显示我想要的那个.try {ManagementClass Management = new ManagementClass("Win32_OperatingSystem");foreach (ManagementObject Object in Management.GetInstances()){foreach (PropertyData Data in Object.Properties){if (Data.Name.Equals("CSName") && (Data...

c# – 为什么在从表中选择值时排除NULL值【代码】

我写了一个sql查询来获取所有记录但不具体. 我的表有一个INT类型的column3,也可以有一些null值.但是以下查询忽略了column3中具有NULL的记录. 表格1:ID | Column1 | Column2 | Column3 1 xyz xyz 200 2 xyz xyz 201 3 xyz xyz NULL 4 xyz xyz NULL 5 xyz xyz 201SQL查询:SELECT [ID], [Column1], [Column2], [Column3] // (int, null) FRO...

框架 - 相关标签