我正在做Microsoft的MVC入门教程:
这包括创建代码优先数据库.
一切正常,但我无法找到我的数据库.
这是我的ConnectionString:
<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>
Run Code Online (Sandbox Code Playgroud)
如果我调试我的索引方法连接如下:
Data Source=.\SQLEXPRESS; Integrated Security=True
Run Code Online (Sandbox Code Playgroud)
但是我的SQLEXPRESS实例中没有数据库,我已经使用SQL Server Management Studio进行了检查.
如果我搜索我的文件系统,我也找不到任何东西*.mdf.
App_Data 在我的项目是空的...
但是所有的CRUD操作都运行良好,必须有一些东西.
我能看到该表的唯一方法是.\SQLEXPRESS通过Visual Studio Server Explorer连接.但这个位置在哪里?如果我.\SQLEXPRESS通过SQL Server Management Studio 连接,为什么我看不到该表?
任何的想法?
我正在编写一个明显错误的 C# 代码。我正在尝试使用 WMI 查询获取随身碟数据,并在继续操作后,检查查询是否返回 0 行以避免错误。
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_USBDevice");
ManagementObjectCollection drive = searcher.Get();
if (drive == null)
{
MessageBox.Show("Failed to read data.");
Application.Exit();
}
Run Code Online (Sandbox Code Playgroud)
显然这个drive == null方法是行不通的。我怎样才能以正确的方式检查它?而且,这是获取随身碟数据的正确方法吗?
我想为mvc页面制作一个这样的模型:
public class Body
{
public int Id { get; set; }
public class Hand
{
public List<Fingers> fingers { get; set; }
}
public class Foot
{
public List<Toes> toes { get; set; }
}
public class Head
{
public Nose nose {get; set;}
public List<Ears> ears { get; set; }
public List<Eyes> eyes { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个像这样的手指类:
public class Fingers
{
public int Id { get; set; }
public string Description { get; set; } …Run Code Online (Sandbox Code Playgroud) 为什么此代码无效?很确定它在 C /C++ 中是合法的
伪代码:
String s = Console.ReadLine();
int x = 0;
Int32.TryParse(s, out x) ? Console.WriteLine("Foo") : Console.WriteLine("bar");
Run Code Online (Sandbox Code Playgroud) 我有一个对象,其中包含一个具有另一个对象类型的属性,我想将其视为复杂类型。
public class Location : IModule
{
public string Id { get; set; }
public Coordinate Coordinate { get; set; }
}
[ComplexType]
public class Coordinate
{
public string Latitude { get; set; }
public string Longitude { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在添加迁移时,我遇到了需要主键的问题(正是我想要防止的)。
实体类型Coordinate需要定义一个主键。
编辑
出于性能原因,我希望将属性存储为Coordinate_Latitude而Coordinate_Longitute不是引用另一个表。
我想实现一个async功能。我的问题是;我不知道将等待关键字放在下面的代码中:
public async Task<List<ManualReadTag>> GetManuallyReadTags(ParameterManualTags model)
{
var db = new ApplicationDbContext();
using (var cnxn = db.Database.Connection)
{
cnxn.Open();
var cmd = cnxn.CreateCommand();
cmd.CommandText = "GetManualReadForDedicated";
cmd.CommandType = CommandType.StoredProcedure;
var dtFrom = cmd.CreateParameter();
dtFrom.ParameterName = "@DateFrom";
dtFrom.DbType = DbType.Date;
dtFrom.Direction = ParameterDirection.Input;
dtFrom.Value = model.DateFrom;
var dTo = cmd.CreateParameter();
dTo.ParameterName = "@DateTo";
dTo.DbType = DbType.Date;
dTo.Direction = ParameterDirection.Input;
dTo.Value = model.DateTo;
var lane = cmd.CreateParameter();
lane.ParameterName = "@Lane";
lane.DbType = DbType.Int32;
lane.Direction = ParameterDirection.Input;
lane.Value = model.Lane;
var …Run Code Online (Sandbox Code Playgroud) 我有一个模型类:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我用这个添加两个列表时:
List<Person> people1 = new List<Person> {
new Person() { Id = 1, Name = "Name1" },
new Person() { Id = 2, Name = "Name2" },
new Person() { Id = 3, Name = "Name3" },
};
List<Person> people2 = new List<Person> {
new Person() { Id = 1, Name = "Name1" },
new Person() { Id = 4, …Run Code Online (Sandbox Code Playgroud) 我想打印这样的数据:
http://www.csharp-examples.net/align-string-with-spaces/
------------------------------- Bi1l | Gates | 51 EdnA | Parker | 114 JohNny | Depp | 44 -------------------------------
我尝试使用上面的例子,PadRight以及PadLeft更多的长度计算,我总是得到这种类型的输出(我的输出转到a TextBox)
------------------------------- Bill | Gates | 51 Edna | Parker | 114 Johnny | Depp | 44 -------------------------------
对于我的想法,它发生是因为WPF不为每个字符提供固定和相等的块,因此W占用更多的空间i,并使分离看起来很糟糕.
有人可以帮我解决问题吗?
我有一个ComboBox我放在SourceGrid3控件中,但由于某种原因我无法设置Enabled属性true.
这是我的代码.
ComboBox cboMyComboBox = new ComboBox();
cboMyComboBox.Enabled = true;
cboMyComboBox.BeginUpdate();
cboMyComboBox.Items.AddRange(new object[] { "Accept", "Reject" });
cboMyComboBox.EndUpdate();
cboMyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
SourceGrid3.Cells.Real.CellControl thisControl = new SourceGrid3.Cells.Real.CellControl(cboMyComboBox);
myGrid[row, column] = thisControl;
Run Code Online (Sandbox Code Playgroud)
(myGrid是SourceGrid3网格)
出于某种原因,当最后一行被执行时,该Enabled值将转向false并且后续尝试更改它(如将其设置回true)不会产生任何影响.
即使我尝试true在Visual Studio调试器中更改值,它也不会允许它,只需将其更改回false.我已经看过了ReadOnly这个字段属性,但似乎并没有成为一个(除非我失去了一些东西),而且我不能改变其他属性(如RightToLeft从No到Yes)
还有什么我可以检查可能会导致这种控制被强制执行false吗?
我有一段代码如下:
IDictionary<string, string> dictionary = new Dictionary<string, string>(){
{ "de-DE", "German"},
{ "en?GB", "English"},
{ "en?US", "English"},
{ "es?ES", "Spanish"},
{ "es?MX", "Spanish"},
{ "fr?CA", "French"},
{ "fr?FR", "French"},
{ "hu?HU", "Hungarian"},
{ "pl?PL", "Polish"},
{ "pt?PT", "Portuguese"},
{ "nl?NL", "Dutch"},
{ "nb?NO", "Norwegian"},
{ "sv?SE", "Swedish"},
{ "it?IT", "Italian"},
};
bool check = dictionary.ContainsKey("en-US");
Console.WriteLine(check);
Run Code Online (Sandbox Code Playgroud)
的check回报false.有人可以帮忙解释一下吗?
c# ×10
.net ×4
asp.net-mvc ×2
alignment ×1
async-await ×1
combobox ×1
dictionary ×1
list ×1
primary-key ×1
razor ×1
sql-server ×1
string ×1
winforms ×1
wmi ×1
wpf ×1