小编qak*_*mak的帖子

实体框架5中的ExecuteStoreCommand方法在哪里?

我在VS2012中使用EF5,我试图删除某些表的所有数据ExecuteStoreCommand,如下所示:

ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]");
Run Code Online (Sandbox Code Playgroud)

但问题是EF告诉我,方法ExecuteStoreCommand未找到.我不明白为什么?

你能告诉我为什么吗?或者给我一个高效的解决方案删除表格的所有数据.

c# entity-framework entity-framework-5 visual-studio-2012

30
推荐指数
1
解决办法
2万
查看次数

在MVC上执行Edit时如何保留某些字段的原始值?

如您所知,当我们想要修改数据时,我们将转到编辑页面:

public ActionResult EditAdmin(int UserId)
{ 
        User user = persons.Users.Find(id);
        return View(user);
}
Run Code Online (Sandbox Code Playgroud)

然后我们在编辑页面上提交它,它将修改:

public ActionResult EditAdmin(User user)
{ 
        persons.Entry(user).State = EntityState.Modified;
        persons.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

但问题是,我有很多字段不需要修改:

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
}
Run Code Online (Sandbox Code Playgroud)

显然,我无法在我的编辑页面上显示某些字段使用隐藏,因为我不希望它在UI上显示.但是当提交时,我仍然需要它仍然保留原始值.那么它有什么好主意吗?谢谢

UPDATE1:

为什么我不能用

entry.Property(e => …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc entity-framework

13
推荐指数
3
解决办法
3万
查看次数

如何在EntityFramework 5中使用Transaction?

我想同时转换一些表.如果一个人不成功,必须全部回滚.

像这样的东西:

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");
Run Code Online (Sandbox Code Playgroud)

但问题是,我不知道如何使用交易.

我试着这个:

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();
}
Run Code Online (Sandbox Code Playgroud)

这里的问题: tr.Commit(); 和Exception告诉我:

{System.InvalidOperationException: Connection must be valid and open to rollback transaction
Run Code Online (Sandbox Code Playgroud)

tr.Rollback();抛出异常.例外是:

{System.InvalidOperationException: Connection must …
Run Code Online (Sandbox Code Playgroud)

c# mysql entity-framework entity-framework-5 visual-studio-2012

9
推荐指数
1
解决办法
2万
查看次数

如何在代码中动态计算WPF所有摄像机设置?

我在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
Run Code Online (Sandbox Code Playgroud)

现在我希望图像显示就像它是原始的2d窗口(看起来没什么变化,但实际上图像是3d).

但问题是如果我希望它看起来与WPF原始相同,我必须更改一些相机设置,如PerspectiveCamera.PositionMeshGeometry3D.Position.因为Viewport3D当窗口改变大小时会动态改变大小,我必须动态计算Viewport3D设置.反正有吗?

我已经尝试过了,但无法正确计算: …

.net c# wpf

9
推荐指数
1
解决办法
663
查看次数

我应该如何从每个对象中禁用Entity Framework表引用(外部)列表?

我正在使用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();
}
Run Code Online (Sandbox Code Playgroud)

还有AllPersons.student集合将包含在结果中;

但我不需要它.当然这只是一个例子,有很多大表有这么多的引用,因此它总是存在性能问题.

所以我试图不让它出现在我的结果中.所以我改变它:

using (var ctx = new myEntities)
{
      ctx.Configuration.ProxyCreationEnabled = false;
      ctx.Configuration.LazyLoadingEnabled = false;
      AllPersons= ctx.Persons.ToList();
}
Run Code Online (Sandbox Code Playgroud)

现在很好,因为AllPersons.student收集将永远null

但现在我发现:如果我和同学一起学习:

using (var ctx = new myEntities)
{
    ctx.Configuration.ProxyCreationEnabled = false;
    ctx.Configuration.LazyLoadingEnabled = false;
    AllPersons= ctx.Persons.ToList();
    AllStudents = ctx.Student.ToList();
}
Run Code Online (Sandbox Code Playgroud)

现在参考仍然包括在内.

那么在这种情况下,有没有让参考包含在任何时间?谢谢.


更新 …

c# .net-4.0 system.data.sqlite entity-framework-5

8
推荐指数
1
解决办法
4665
查看次数

使用CustomErrors删除aspxerrorpath param使用ResponseRewrite

我正在使用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>
Run Code Online (Sandbox Code Playgroud)

我还将错误操作更改为:

public ActionResult Error()
{
    Response.Status = "404 Not Found";
    Response.StatusCode = 404;
    return View();
}
Run Code Online (Sandbox Code Playgroud)

现在会发生404事件.我的URL上总是有aspxerrorpath param. 我尝试添加redirectMode="ResponseRewrite"到customError节点但是如果添加这个,错误将显示运行时异常.....

那么有没有最好的方法来删除aspxerrorpath param?谢谢.

custom-error-pages asp.net-mvc-4

7
推荐指数
2
解决办法
8407
查看次数

如果操作系统低于Win10,则在使用从右到左语言时,GraphicsPath AddString对字体的支持不足

我需要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), …
Run Code Online (Sandbox Code Playgroud)

.net c# windows gdi+ gdi

7
推荐指数
1
解决办法
186
查看次数

禁用 nullable 的目的是什么?将来禁用它时我们如何使用它?

从 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; } 
Run Code Online (Sandbox Code Playgroud)

2. 林克:

Person model = PersenList.Where(x => x.id == id).FirstOrDefault();
if (null != model)
{
   // Do something
} …
Run Code Online (Sandbox Code Playgroud)

.net c#

7
推荐指数
1
解决办法
2538
查看次数

WPF win8平板电脑模式键盘隐藏屏幕底部的项目

我目前正在使用WPFWIN8表模式设计一些软件.

有些地方需要输入一些使用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>
Run Code Online (Sandbox Code Playgroud)

但现在我发现键盘是否专注于某些不在顶部的文本框,可能在中间或者可能在底部.键盘将覆盖它.我甚至看不到我在输入的内容.(如图片所示)

在此输入图像描述

那么有什么好方法可以解决它吗?谢谢.

PS:我试图拖动键盘,但看起来它不是一个好的解决方案,因为中间的一些文本框,键盘仍将覆盖中间的哪个文本框.

c# wpf .net-4.0

6
推荐指数
1
解决办法
1487
查看次数

Visual Studio抛出输出:在MVC 5 Razor页面上解除引用ViewBag.property的RuntimeBinderException

我使用ASP.NET MVC 5Entity 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;
Run Code Online (Sandbox Code Playgroud)

我的项目剃刀页面使用所有ViewBag属性,所以有时我可以看到很多RuntimeBinderException事件.它只输出 - 从不触发任何东西 - 直到我在Visual Studio上检查公共语言运行时异常

发生什么了?反正有没有隐藏它?为什么现在显示?为什么以前没有显示?

c# asp.net-mvc asp.net-4.5 visual-studio-2013 asp.net-mvc-5.2

5
推荐指数
0
解决办法
585
查看次数