我在VS2012中使用EF5,我试图删除某些表的所有数据ExecuteStoreCommand,如下所示:
ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]");
但问题是EF告诉我,方法ExecuteStoreCommand未找到.我不明白为什么?
你能告诉我为什么吗?或者给我一个高效的解决方案删除表格的所有数据.
如您所知,当我们想要修改数据时,我们将转到编辑页面:
public ActionResult EditAdmin(int UserId)
{ 
        User user = persons.Users.Find(id);
        return View(user);
}
然后我们在编辑页面上提交它,它将修改:
public ActionResult EditAdmin(User user)
{ 
        persons.Entry(user).State = EntityState.Modified;
        persons.SaveChanges();
}
但问题是,我有很多字段不需要修改:
public class User{
    public int UserId {get; set;} // do not need modify
    public int Password {get; set;} // do not need modify
    public string Name {get; set;}
    public bool Sex {get; set;}
    public DateTime AddTime {get; set;} // do not need modify
}
显然,我无法在我的编辑页面上显示某些字段使用隐藏,因为我不希望它在UI上显示.但是当提交时,我仍然需要它仍然保留原始值.那么它有什么好主意吗?谢谢
UPDATE1:
为什么我不能用
entry.Property(e => …我想同时转换一些表.如果一个人不成功,必须全部回滚.
像这样的东西:
ctx.Database.ExecuteSqlCommand("truncate table tb_expensesall");
ctx.Database.ExecuteSqlCommand("truncate table tb_wholesale");
ctx.Database.ExecuteSqlCommand("truncate table tb_singlesale");
ctx.Database.ExecuteSqlCommand("truncate table tb_purchase");
但问题是,我不知道如何使用交易.
我试着这个:
using (gasstationEntities ctx = new gasstationEntities(Resources.CONS))
{
    ctx.Database.Connection.Open();
    DbTransaction tr = ctx.Database.Connection.BeginTransaction();
    try
    {
        ctx.Database.ExecuteSqlCommand("truncate table tb_expensesall");
        ctx.Database.ExecuteSqlCommand("truncate table tb_wholesale");
        ctx.Database.ExecuteSqlCommand("truncate table tb_singlesale");
        ctx.Database.ExecuteSqlCommand("truncate table tb_purchase");
        //commit the transaction
        tr.Commit();
        new MessageWindow(this, Resources.GetString("Warn"), Resources.GetString("DeleteSuccess"));
    }
    catch (Exception ex)
    {
        //return
        tr.Rollback();
    }
    //close
    ctx.Database.Connection.Close();
}
这里的问题:   tr.Commit();
和Exception告诉我:
{System.InvalidOperationException: Connection must be valid and open to rollback transaction
而tr.Rollback();抛出异常.例外是:
{System.InvalidOperationException: Connection must …c# mysql entity-framework entity-framework-5 visual-studio-2012
我在Window中有Viewport3D.当窗口大小改变时,它将改变大小.
<Window>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="100"/>
      <RowDefinition/>
    <Grid.RowDefinitions>
    <Label Grid.Row="0" Content="top label"/>
    <Viewport3D Grid.Row="1" x:Name="vp3D" >
            <Viewport3D.Camera >
                 <PerspectiveCamera x:Name="pCamera"  LookDirection="0 0 -1" UpDirection="0 1 0" />
            </Viewport3D.Camera>
            <Viewport2DVisual3D x:Name="v2dv3d">
                  <Viewport2DVisual3D.Geometry>
                      <MeshGeometry3D x:Name="mg3d" TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
                   </Viewport2DVisual3D.Geometry>
                   <Viewport2DVisual3D.Material>
                         <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
                   </Viewport2DVisual3D.Material>
                          <Image  Height="{Binding ElementName=vp3D, Path=ActualHeight}" Width="{Binding ElementName=vp3D, Path=ActualWidth}" Stretch="Fill"/>
            </Viewport2DVisual3D>
            <ModelVisual3D>
                 <ModelVisual3D.Content>
                      <DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
                 </ModelVisual3D.Content>
           </ModelVisual3D>
  </Viewport3D>
 </Grid>
</Window
现在我希望图像显示就像它是原始的2d窗口(看起来没什么变化,但实际上图像是3d).
但问题是如果我希望它看起来与WPF原始相同,我必须更改一些相机设置,如PerspectiveCamera.Position或MeshGeometry3D.Position.因为Viewport3D当窗口改变大小时会动态改变大小,我必须动态计算Viewport3D设置.反正有吗?
我已经尝试过了,但无法正确计算: …
我正在使用Sqlite数据库和System.Data.SQLite 1.0.92 这里有2个表:
表人:
PERSONID
PERSONNAME
表学生:
学生卡
PersonId(参考表人FK)
StudentNo
现在每次我在EF5中获得Persons Collection:
using (var ctx = new myEntities)
{
  AllPersons = ctx.Persons.ToList();
}
还有AllPersons.student集合将包含在结果中;
但我不需要它.当然这只是一个例子,有很多大表有这么多的引用,因此它总是存在性能问题.
所以我试图不让它出现在我的结果中.所以我改变它:
using (var ctx = new myEntities)
{
      ctx.Configuration.ProxyCreationEnabled = false;
      ctx.Configuration.LazyLoadingEnabled = false;
      AllPersons= ctx.Persons.ToList();
}
现在很好,因为AllPersons.student收集将永远null
但现在我发现:如果我和同学一起学习:
using (var ctx = new myEntities)
{
    ctx.Configuration.ProxyCreationEnabled = false;
    ctx.Configuration.LazyLoadingEnabled = false;
    AllPersons= ctx.Persons.ToList();
    AllStudents = ctx.Student.ToList();
}
现在参考仍然包括在内.
那么在这种情况下,有没有让参考包含在任何时间?谢谢.
更新 …
我正在使用asp.net MVC4 + visual studio 2012.一切都很好,但只有自定义错误总是在URL上有aspxerrorpath参数.
我已经在web.config上配置了自定义错误:
<customErrors mode="On" defaultRedirect="~/Error/Error">
  <error redirect="~/Error/Error" statusCode="404" />
  <error redirect="~/Error/Error" statusCode="500" />
</customErrors>
我还将错误操作更改为:
public ActionResult Error()
{
    Response.Status = "404 Not Found";
    Response.StatusCode = 404;
    return View();
}
现在会发生404事件.我的URL上总是有aspxerrorpath param.
我尝试添加redirectMode="ResponseRewrite"到customError节点但是如果添加这个,错误将显示运行时异常.....
那么有没有最好的方法来删除aspxerrorpath param?谢谢.
我需要generate an image from a string在我的WPF应用程序中显示它.这是我的代码:
// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();
// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);
// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();
// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("?????123456789?????", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), …从 C# 10 开始,默认情况下将禁用 Nullable。
我已经看过很多关于 Nullable 的文章和视频,他们只是说我们不再担心 Null 引用异常。
他们还一直说有很多方法可以使用它:,,,,Disable..... bla bla bla。EnableWarningAnnotations
他们向我们介绍了很多使用它的方法:?.,,,,,...  等????=NotNullWhenTrueNotNullWhenFalse
但我没有看到有人告诉我们:禁用时如何使用它。
我们之前有很多场景可以使用null。
1. 财产:
// What is the default value when nullable disabled , and how way we should use it?
Public string Name { get; set; } 
2. 林克:
Person model = PersenList.Where(x => x.id == id).FirstOrDefault();
if (null != model)
{
   // Do something
} …我目前正在使用WPF和WIN8表模式设计一些软件.
有些地方需要输入一些使用Textbox的数字.
我用某种方式最终显示键盘:http://brianlagunas.com/showing-windows-8-touch-keyboard-wpf/
但是我发现,有时键盘会在它出现后覆盖底部或中间的某些项目.
例如:我在屏幕上有5个文本框
<Grid>
  <TextBox HorizontalAlignment="Left" Margin="500,95,0,0"  Height="23" Width="120"/>
  <TextBox HorizontalAlignment="Left" Margin="500,295,0,0"  Height="23" Width="120"/>
  <TextBox HorizontalAlignment="Left" Margin="500,495,0,0"  Height="23" Width="120"/>
  <TextBox HorizontalAlignment="Left" Margin="500,695,0,0"  Height="23" Width="120"/>
  <TextBox HorizontalAlignment="Left" Margin="500,800,0,0"  Height="23" Width="120"/>
</Grid>
但现在我发现键盘是否专注于某些不在顶部的文本框,可能在中间或者可能在底部.键盘将覆盖它.我甚至看不到我在输入的内容.(如图片所示)
那么有什么好方法可以解决它吗?谢谢.
PS:我试图拖动键盘,但看起来它不是一个好的解决方案,因为中间的一些文本框,键盘仍将覆盖中间的哪个文本框.
我使用ASP.NET MVC 5与Entity Framework 6
今天我用的NuGet(例如更新的某些组件MVC 5.2.0.0更新MVC 5.2.2.0),也更新EF6到新版本以及其他成分.
但现在Visual Studio输出窗口始终显示:
类型的第一次机会异常
Microsoft.CSharp.dll中出现"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException"
然后我打开例外面板并选择公共语言运行时异常(在Visual Studio中2013:按Ctrl + Alt + E),然后我找到了我的每一页剃刀源ViewBag:
ViewBag.Title = Resource.ApplicationName;
我的项目剃刀页面使用所有ViewBag属性,所以有时我可以看到很多RuntimeBinderException事件.它只输出 - 从不触发任何东西 - 直到我在Visual Studio上检查公共语言运行时异常
发生什么了?反正有没有隐藏它?为什么现在显示?为什么以前没有显示?
c# asp.net-mvc asp.net-4.5 visual-studio-2013 asp.net-mvc-5.2
c# ×9
.net ×4
.net-4.0 ×2
asp.net-mvc ×2
wpf ×2
asp.net-4.5 ×1
gdi ×1
gdi+ ×1
mysql ×1
windows ×1