小编Chr*_*ris的帖子

如何组织彼此继承的C#类,还具有彼此继承的属性?

我有一个应用程序,它有一个概念,Venue即事件发生的地方.A Venue有很多个VenuePart.所以,它看起来像这样:

public abstract class Venue
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<VenuePart> VenueParts { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

A Venue可以GolfCourseVenue是a Venue,具有Slope和特​​定类型的VenueParta HoleVenuePart:

public class GolfCourseVenue : Venue
{
    public string Slope { get; set; }
    public virtual ICollection<HoleVenuePart> Holes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在未来,可能还有其他种类的Venues都继承自Venue.他们可能会添加自己的字段,并且将始终具有VenuePart自己的特定类型.

以下是VenuePart课程:

public abstract …
Run Code Online (Sandbox Code Playgroud)

c# oop entity-framework

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

在Web应用程序中使用WPF程序集是否可以?

我有一个针对.NET 4的ASP.NET MVC 2应用程序,需要能够动态调整图像大小并将其写入响应.

我有代码,这样做,它的工作原理.我正在使用System.Drawing.dll.

但是,我想增强我的代码,这样不仅可以调整图像大小,而且还可以将其从24bpp降低到4bit灰度.在我的生活中,我无法找到有关如何使用System.Drawing.dll执行此操作的代码.

但我确实发现了一堆WPF的东西.这是我的工作/示例代码(在LinqPad中运行).

// Load the original 24 bit image
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(@"C:\Temp\Resized\18_appa2_015.png", UriKind.Absolute);
//bitmapImage.DecodePixelWidth = 600;
bitmapImage.EndInit();

// Create the destination image
var formatConvertedBitmap = new FormatConvertedBitmap();
formatConvertedBitmap.BeginInit();
formatConvertedBitmap.Source = bitmapImage;
formatConvertedBitmap.DestinationFormat = PixelFormats.Gray4;
formatConvertedBitmap.EndInit();

// Encode and dump the image to disk
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(formatConvertedBitmap));
using (var fileStream = File.Create(@"C:\Temp\Resized\18_appa2_015_s2.png"))
{
    encoder.Save(fileStream);
}
Run Code Online (Sandbox Code Playgroud)

它使用System.Xaml.dll,WindowsBase.dll,PresentationCore.dll和PresentationFramework.dll.使用的名称空间是:System.Windows.Controls,System.Windows.Media和System.Windows.Media.Imaging.

在我的Web应用程序中使用这些命名空间有什么问题吗?这似乎不对.

如果有人知道如何在没有所有这些WPF的东西(我几乎不理解,BTW)下降深度,我会很高兴看到它.

asp.net wpf asp.net-mvc

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

任何人都知道为什么这样:在CSS不能在IE9中工作?

此提交按钮应在左侧舍入,并指向右侧.它在非ie浏览器中工作,但在IE9中,它不起作用.

如果我查看开发人员工具中的样式,.flat-button:在规则之后将所有内容划掉,就像它被某些东西取代一样.什么?

<button type="submit" class="flat-button">Submit</button>
<style>
.flat-button {
    float: left;
    position: relative;
    border-top-left-radius: 5px;
    -moz-border-top-left-radius: 5px;
    -webkit-border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    -moz-border-bottom-left-radius: 5px;
    -webkit-border-bottom-left-radius: 5px;
    border: none;
    padding: 0 12px;
    margin: 0 3px 3px 0;
    outline: none;
    cursor: pointer;
    color: white;
    font-family:'Trebuchet MS', Arial, helvetica, Sans-Serif;
    font-size: 14px;
    font-weight: bold;
    font-style: italic;
    text-decoration: none;
    border-collapse: separate;
    height: 26px;
    line-height: 26px;
    background: #5191cd;
}
.flat-button:hover {
    background: #1c3f95;
}
.flat-button:after {
    position: absolute;
    content: ' ';
    height: 0;
    width: 0;
    left: …
Run Code Online (Sandbox Code Playgroud)

css pseudo-element internet-explorer-9

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

在kendo网格中,我可以使用函数动态设置列属性吗?

我在这里有一些代码,我试图根据数据项的值设置单元格的背景颜色:http://dojo.telerik.com/@solidus-flux/eHaMu

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.common.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.rtl.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.mobile.all.min.css">

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.3.1411/js/kendo.all.min.js"></script>
</head>
<body>

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [ {
    field: "name",
    title: "Name",
    attributes: function(e) {
      return {
        "class": "table-cell",
        style: e.name == "Jane Doe" ? "background-color: red" : "background-color: green"
      };
    }
    //attributes: {
      //"class": "table-cell",
      //style: "text-align: right; font-size: 14px"
    //}
  } ], …
Run Code Online (Sandbox Code Playgroud)

javascript kendo-ui kendo-grid kendo-template

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

如何在 Entity Framework Core 3.1 中对自定义对象执行原始 SQL 查询,而无需迁移想要创建表?

我正在查询一个Store表以向用户显示 10 个最接近的Stores。我想,以显示NameDistanceStore,但更喜欢保持距离在自定义实体。

Store字段:IdNameLatitudeLongitude,等
StoreDto字段:Id,姓名,Distance`

这个 SO 答案让我们走上了正确的轨道,尤其是评论。但是,现在不推荐使用 DbQuery。

Keyless Entity Types上的文档说我们可以使用 Keyless Entity Type 作为原始 SQL 查询的返回类型。

我的 DbContext 已经有:

public DbSet<Store> Stores { get; set; }
Run Code Online (Sandbox Code Playgroud)

添加

public DbSet<StoreDto> StoreDtos { get; set; }
Run Code Online (Sandbox Code Playgroud)

modelBuilder.Entity<QuestSiteDto>()
    .HasNoKey()
    .ToView(null); // Hack to prevent table generation
Run Code Online (Sandbox Code Playgroud)

允许我的商店搜索代码工作。但是下次我运行迁移时,EF Core 想要创建一个 StoreDto 表,除非我添加那个丑陋的ToView(null)hack。

作为参考,这是我的查询: …

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

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

在Visual Studio 2010中,如何在MVC应用程序中调用"在浏览器中查看"功能?

在Visual Studio 2010中,您可以在Web窗体应用程序中右键单击aspx页面,或者在解决方案资源管理器中右键单击Web窗体应用程序本身,然后在上下文菜单中获得"在浏览器中查看".

在ASP.NET MVC项目中,此项似乎在上下文菜单中不可用.我知道运行应用程序的唯一方法是将MVC应用程序设置为启动项目并按CTRL + F5.但是,如果解决方案中有两个MVC应用程序,则这不起作用.你如何为mvc应用程序实现这一目标?

asp.net-mvc visual-studio-2010

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

加密字符串时重用 AES 对象是否安全?

我在加密大量字符串的应用程序中遇到一些性能问题。大多数 CPU 使用发生在我从名为 Encrypt() 的公共方法调用私有方法 getAes() 时:

public static class CryptKeeper
{
    const int HASH_SIZE = 32; //SHA256

    /// <summary>
    /// Encrypts a string message. Includes integrity checking.
    /// </summary>
    public static string Encrypt(string messageToEncrypt, string sharedSecret, string salt)
    {
        // Prepare message with hash
        var messageBytes = Encoding.UTF8.GetBytes(messageToEncrypt);
        var hashedMessageBytes = new byte[HASH_SIZE + messageBytes.Length];
        var hash = Utilities.GenerateSha256Hash(messageBytes, 0, messageBytes.Length);
        Buffer.BlockCopy(hash, 0, hashedMessageBytes, 0, HASH_SIZE);
        Buffer.BlockCopy(messageBytes, 0, hashedMessageBytes, HASH_SIZE, messageBytes.Length);

        // Encrypt message
        using (var aes = getAes(sharedSecret, …
Run Code Online (Sandbox Code Playgroud)

.net c# security aes

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

如何将ASP.NET 5(vNext)用户机密注入我自己的实用程序类?

我已经用过:
user-secret set "AWSAccessKey" "my access key"
user-secret set ""AWSSecretKey" "my secret key"

让我的钥匙进入秘密商店.

我有这个课程,我将用它来通过Amazon SES发送电子邮件,但我不知道如何将我的密钥插入其中.

public class MailHelper
{
    public void SendEmailSes(string senderAddress, string receiverAddress, string subject, string body)
    {
        using (var client = new AmazonSimpleEmailServiceClient(
            new BasicAWSCredentials("[AWSAccessKey]", "[AWSSecretKey]"),
            RegionEndpoint.USEast1))
        {
            var sendRequest = new SendEmailRequest
            {
                Source = senderAddress,
                Destination = new Destination { ToAddresses = new List<string> { receiverAddress } },
                Message = new Message
                {
                    Subject = new Content(subject),
                    Body = new Body { Text …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dependency-injection asp.net-core

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

量化<p>的语义值而不是<div>

我正在将一些我无法控制的XML转换为XHTML.XML模式定义了一个<para>段落,并标记<unordered-list><ordered-list>对列表.

经常在这个XML中,我发现嵌套在段落中的列表.因此,直接转换会导致<ul>s嵌套在<p>s中,这在XHTML中是非法的.

我已经创建了一个处理它的方法列表,这是最明显的:

  1. 只是不要担心.浏览器会很好.谁在乎.(我不喜欢这个选项,但它是一个选项!)
  2. 在我的转换中写一个fancy-pants组件,确保所有<para>标签在无序列表开始之前关闭,然后重新打开.(我最喜欢这个选项,但由于嵌套的级别很复杂,我们可能没有预算)
  3. 只是变换<para><div>并设置了div的边缘,所以它看起来像在浏览器中的一个段落.这是发布有效XHTML的最简单的解决方案,但它取自标记的语义值.

我的问题是:

  • 如果选择3,我会失去多少价值?
  • 它是否真的重要吗?
  • 对用户体验的实际影响是什么?
  • 如果你能引用参考文献,请做(这很容易推测).例如,我认为它可能会影响我们正在使用的Google Search Appliance的搜索结果.
  • 如果搜索词出现在div中,它们的重量是否较轻?
  • 或者它们与前面的标题标记之间的关联是否较少?

我怎么能找到这个?

html xhtml

5
推荐指数
1
解决办法
149
查看次数

如何通过 FTP 访问我的 Azure 应用服务文件?wwwroot 目录为空

使用 Azure 门户中应用服务页面导航上的部署中心链接,我能够找到我的 FTP 凭据并使用它们轻松登录。但是,wwwroot 文件夹中除了hostingstart.html 之外没有任何文件。

空 wwwroot

但是,当我使用 Azure 控制台时,我的所有文件都出现在 wwwroot 文件夹中,而 Hostingstart.html 文件不在那里。

天蓝色控制台显示文件

我不确定它是否相关,但我们确实有持续集成设置。我只是希望能够查看这些文件并与它们交互。

如果我浏览到 /LogFiles 文件夹,我可以确认 FTP 和 Azure 命令行显示相同的文件。所以我知道我在正确的服务器上。

ftp azure

5
推荐指数
1
解决办法
4074
查看次数