我正在尝试执行以下代码并收到错误
public List<Log> GetLoggingData(DateTime LogDate, string title)
{
var context = new LoggingEntities();
var query = from t in context.Logs
where t.Title == title
&& t.Timestamp == LogDate
select t;
return query.ToList();
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误是"LINQ to Entities不支持指定的类型成员'Date'.仅支持初始值设定项,实体成员和实体导航属性." 我已尝试过将各种符号转换为字符串的各种尝试,只比较日期部分,但似乎无法获得正确的组合.任何帮助是极大的赞赏.
我正在使用EntityFramework和"代码优先"方法进行迁移.
我已经成功地从我的模型中生成了表格,但是这些列是按字母顺序添加的,而不是我模型中的顺序.
我试过这个:
[Key, Column(Order=0)]
public int MyFirstKeyProperty { get; set; }
[Column(Order=1)]
public int MySecondKeyProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有奏效.
如何手动设置数据库中字段的顺序?
我使用的是ASP.NET Core和EF Core(SqlServer)v1.1.0.
c# entity-framework entity-framework-core asp.net-core asp.net-core-1.0
我有一个带有静态构造函数的静态类.我需要以某种方式将参数传递给这个静态类,但我不确定最好的方法是什么.你会推荐什么?
public static class MyClass {
static MyClass() {
DoStuff("HardCodedParameter")
}
}
Run Code Online (Sandbox Code Playgroud) 我正在与EF合作.我正在尝试执行此行
public ActionResult Edit(string id)
{
return View(obj.FindSemesterById(id));
}
Run Code Online (Sandbox Code Playgroud)
我在我的项目上安装了EF Version 5.
但我得到这个错误:
无法加载文件或程序集'EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
我的web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="EducationDBEntities" connectionString="metadata=res://*/EducationModel.csdl|res://*/EducationModel.ssdl|res://*/EducationModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=EducationDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add …Run Code Online (Sandbox Code Playgroud) 我正在尝试Portable Class Library使用ASP.NET Core 1.0以下指令编写代码:
public static void WriteMessage<T>(T value)
{
if (typeof(T).IsEnum)
{
Debug.Print("Is enum")
}
else
{
Debug.Print("Not Is enum")
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码没有编译,因为编译器说IsEnumType上没有属性.
有什么建议?
我有两个可以为空的日期时间对象,我想比较两者.最好的方法是什么?
我已经尝试过了:
DateTime.Compare(birthDate, hireDate);
Run Code Online (Sandbox Code Playgroud)
这是一个错误,也许是期待类型的日期,System.DateTime我有Nullable日期时间.
我也尝试过:
birthDate > hiredate...
Run Code Online (Sandbox Code Playgroud)
但结果不如预期......任何建议?
我有一个运行Server 2008 R2的Web服务器工作组,我正在尝试管理一个检查所有磁盘空间的脚本.我几个月前在设置服务器时设置了这个,我相信它工作正常.现在我去检查并且它发出错误说"RPC服务器不可用".该脚本是一个C#ASP.NET页面,虽然我在PowerShell中尝试过类似的调用但它也会出现同样的错误.该脚本可以正常访问本地计算机的信息,但无法访问远程服务器信息.
我花了最后几个小时挖掘我能找到的一切,但没有任何作用.我已经为WMI(远程和本地),DCOM(远程和本地)以及我正在访问的计算机的整个驱动器设置了权限.我使用了计算机名称,IP地址,完整的计算机名称(xxx.echomountain.com),并尝试在ConnectionOptions对象上进行多次模拟和身份验证设置.
我知道我使用的用户名/密码是正确的,因为我可以访问另一个的分片目录
我可以检查哪些可能导致此错误的任何想法?
ConnectionOptions oConn = new ConnectionOptions();
oConn.Impersonation = ImpersonationLevel.Impersonate;
oConn.EnablePrivileges = true;
oConn.Username = username;
oConn.Password = password;
//oConn.Authentication = AuthenticationLevel.PacketPrivacy;
string strNameSpace = @"\\";
if (srvname != "")
strNameSpace += srvname + ".echomountain.com";
else
strNameSpace += ".";
strNameSpace += @"\root\cimv2";
ManagementScope oMs = new ManagementScope(strNameSpace, oConn);
//get Fixed disk state
ObjectQuery oQuery = new ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
//Get the results
ManagementObjectCollection oReturnCollection …Run Code Online (Sandbox Code Playgroud) 移动我的构建服务器后,我收到以下错误:
C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets (1682): Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x64". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "MSBuildTaskHost.exe" exists and can be run.
我的配置说:
<ConfigurationToBuild Include="Release|Any CPU">
<FlavorToBuild>Release</FlavorToBuild>
<PlatformToBuild>Any CPU</PlatformToBuild>
</ConfigurationToBuild>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
64-bit configuration-files visual-studio msbuild-4.0 tfs2012
我需要在我的动作过滤器中访问当前登录的用户.身份由DelegatingHandler进一步的执行链设置.
我可以访问当前IPrincipal使用HttpContext.Current.User.
到目前为止,我避免使用HttpContext.Current,因为在我看来是坏风格.首先,你的代码只有在IIS中托管时才能工作,其次它包含一个System.Web我认为不会受到伤害的引用,但System.Net.Http如果可能的话,我更愿意坚持使用.
依靠好的旧" HttpContext" 感觉不对.
有没有其他方法可以访问用户的身份ActionFilter?或者,HttpContext如果您不打算运行自托管应用程序,是否可以使用?
authentication iprincipal actionfilterattribute asp.net-web-api
我想在Controller中为我的模型设置一个默认值,但它无法在创建页面中显示.
TestModel代码:
public class TestModel
{
[DataType(DataType.DateTime), Required]
[DisplayFormat(DataFormatString = "yyyy/MM/dd", ApplyFormatInEditMode = true)]
public DateTime StartTime { get; set; }
[DataType(DataType.DateTime), Required]
[DisplayFormat(DataFormatString = "yyyy/MM/dd", ApplyFormatInEditMode = true)]
public DateTime EndTime { get; set; }
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器代码:
public ActionResult Create()
{
var model = new TestModel();
model.StartTime = DateTime.Now;
model.EndTime = DateTime.Now.AddDays(10);
model.Description = "This is a default value";
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
查看页面:
<div class="form-group">
@Html.LabelFor(model => model.StartTime, htmlAttributes: new { @class …Run Code Online (Sandbox Code Playgroud)