小编Lee*_*son的帖子

Linq-to-entities - Include()方法未加载

如果我使用连接,则Include()方法不再有效,例如:

from e in dc.Entities.Include("Properties")
join i in dc.Items on e.ID equals i.Member.ID
where (i.Collection.ID == collectionID) 
select e
Run Code Online (Sandbox Code Playgroud)

e.Properties 没有加载

没有连接,Include()可以工作

背风处

linq entity-framework

46
推荐指数
2
解决办法
5万
查看次数

两个C#扩展泛型方法之间的模糊调用,其中T:class和其他T:struct

考虑两种扩展方法:

public static T MyExtension<T>(this T o) where T:class
public static T MyExtension<T>(this T o) where T:struct
Run Code Online (Sandbox Code Playgroud)

一节课:

class MyClass() { ... }
Run Code Online (Sandbox Code Playgroud)

现在在上面的类的实例上调用extension方法:

var o = new MyClass(...);
o.MyExtension(); //compiler error here..
o.MyExtension<MyClass>(); //tried this as well - still compiler error..
Run Code Online (Sandbox Code Playgroud)

编译器说当我在类上调用它时调用该方法是一个模糊的调用.我原以为它可以确定调用哪个扩展方法,因为MyClass是一个类,而不是一个结构体?

.net c# generics extension-methods

45
推荐指数
3
解决办法
4971
查看次数

带有表格作为项目的CSS Flexbox

我想在包含两个表的DIV上使用CSS flexbox,并使用flex-grow使其中一个表填充可用空间.但是,它没有增长.似乎这是因为表不是块显示元素.如果我将TABLE包装在DIV中,我可以使用它.但是,我想知道是否有没有额外的DIV可以让它工作?

下面是一个例子 - 第一个容器没有DIVS,第二个容器是DIV并且具有理想的布局.

div.container {
    display: flex;
    background-color: red;
}

#nodivs table:first-child {
    background-color: green;
}

#nodivs table:last-child {
    background-color: blue;
    flex-grow: 1;
}



#divs div:first-child {
    background-color: green;
}

#divs div:last-child {
    background-color: blue;
    flex-grow: 1;
}
#divs div:last-child table {
    width: 100%
}
Run Code Online (Sandbox Code Playgroud)
<div id="nodivs" class="container">
    <table>
        <thead>
            <tr><th>T1C1</th><th>T1C2</th><th>T1C3</th></tr>
        </thead>
    </table>
    <table>
        <thead>
            <tr><th>T2C1</th><th>T2C2</th><th>T2C3</th></tr>
        </thead>
    </table>
</div>
<br><br>
<div id="divs" class="container">
    <div><table>
        <thead>
            <tr><th>T1C1</th><th>T1C2</th><th>T1C3</th></tr>
        </thead>
    </table></div>
    <div><table>
        <thead>
            <tr><th>T2C1</th><th>T2C2</th><th>T2C3</th></tr>
        </thead>
    </table></div>
</div>
Run Code Online (Sandbox Code Playgroud)

css flexbox

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

是否值得为多次使用保存typeof()调用的结果?

如果我要在同一类型上使用C#typeof调用的结果,是否值得保存该值,或者只是多次调用typeof().对我来说,多种类型是优选的,因为它可以更简洁,可读的代码.我想这取决于编译器是否会"内联"代码?

.net c# optimization typeof

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

使用Dekstop窗口作为源的DirectShow Source过滤器

我正在寻找一个显示桌面窗口的DirectShow Source过滤器的示例.我确信应该有例子,但我还没有找到它们.也许我使用了错误的术语.

这是为了获取Window的实时输出和处理具有视频的处理.

背风处

directshow

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

从Microsoft.Web.Administration中查找物理路径以及相对于其根目录的路径

我想使用Microsoft.Web.Administration .NET程序集找到IIS网站中的物理路径,相对于网站根目录的路径.

似乎没有一种方法可以做到这一点,但我想知道 - 以下程序是最好的方法吗?:

  1. 获取Microsoft.Web.Administration.Site对象
  2. 找到具有最长路径的应用程序,该路径与路径相对于根的路径的开头相匹配
  3. 从路径的开头相对于根剥离应用程序路径,给出相对于应用程序的路径
  4. 在此应用程序中查找虚拟目录,其中最长路径与路径相对于应用程序的开头相匹配
  5. 从相对于应用程序的路径的开头剥离应用程序路径,提供相对于虚拟目录的路径
  6. 将相对于虚拟目录的路径(交换/ for)附加到虚拟目录的物理路径,以提供我们想要的物理路径

背风处

.net iis-7

5
推荐指数
2
解决办法
2970
查看次数

MEF通用进口

我有以下使用MEF的示例代码:

public interface IFoo<T> 
{}

public class Foo<T> : IFoo<T> 
{}

[Export(typeof(IFoo<String>))]
public class Foo : Foo<String> 
{}

public class Bar<T>
{
   [Import]
   private readonly IFoo<T> foo;
}

static void Main()
{
   var catalog = new AggregateCatalog();
   catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
   var container = new CompositionContainer(catalog);
   container.ComposeParts();

   var bar = new Bar<String>();
   //bar.foo would be null
}
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用 - foo领域是null.这是因为MEF看不到它的类型IFoo<String>吗?

c# generics mef

4
推荐指数
1
解决办法
3634
查看次数