小编Jeh*_*hof的帖子

枚举作为实体框架中的关键5在多对多联接中抛出错误

好吧,这有点冗长/模糊,但我在特定情况下得到一个奇怪的错误,我使用Enum作为表键并尝试查询表,同时包含多个多对多相关实体.

以下示例代码中的错误是:

The type of the key field 'DietIs' is expected to be 'MvcApplication8.Models.DietIs', but the value provided is actually of type 'System.Int32'.
Run Code Online (Sandbox Code Playgroud)

在.net 4.5 Web项目中,我有以下实体配置:

public enum DietIs {
    None,
    Kosher,
    Paleo,
    Vegetarian
}

public class Diet {

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public DietIs DietIs { get; set; }

    public string Description { get; set; }
    public virtual ICollection<Recipe> Recipes { get; set; }
    public virtual ICollection<Menu> Menus { get; set; }
}

public class Recipe {
    public int Id { …
Run Code Online (Sandbox Code Playgroud)

.net enums entity-framework .net-4.5 entity-framework-5

25
推荐指数
1
解决办法
2517
查看次数

在Unity中需要处理?

可能是一个Unity初学者的问题:当使用Unity时,你还需要在你注入的对象上实现Dispose方法吗?或者甚至不需要这样(因此,由Unity自动完成)?这是在Web应用程序的上下文中.

dispose unity-container

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

添加可选参数后System.MissingMethodException

我在一个组件中有一个可选参数之后得到System.MissingMethodException的错误,并且调用它的另一个组件没有构建,因为它使用旧的参数调用它.

只有添加了参数的组件才会构建部署为补丁.调用组件是旧的,因为它没有变化.

当调用组件运行时,它会给出错误:

例外信息

异常类型:System.MissingMethodException消息:找不到方法:'LabelURLs IPSD.BnB.Transaction.Postage.GetLabelURLs(System.String)'.数据:System.Collections.ListDictionaryInternal TargetSite:Void GenerateScanForm(Int32,Int32)HelpLink:NULL源:BnBDispenseQueueProcess

据我所知,它不应该引发错误,因为新参数是可选的.还有一件事是调用组件(EXE)作为Windows服务运行.

我们找到了一个非常有线的解决方法来让它运行.通过删除更改的组件一次并运行调用组件,它将说找不到DLL.再次放置相同的DLL并调用组件工作正常:).

我想我错过了.net的一些内部.

如果需要更多信息,请告诉我.

.net c# missingmethodexception optional-parameters vb.net-2010

24
推荐指数
1
解决办法
7762
查看次数

是否有必要关闭WebInvoke方法的流

我有一个服务接口,其方法具有类型的参数Stream.我应该在读完此流中的所有数据后关闭流,还是在方法调用完成后由WCF运行时完成?

我见过的大多数例子,只读取流中的数据,但不要在Stream上调用Close或Dispose.

通常我会说我不必关闭流因为类不是流的所有者,但原因是为什么问这个问题是我们正在调查我们的系统中的一个问题,一些Android客户端,那个使用HTTP-Post将数据发送到此服务有时具有未关闭的打开连接(使用netstat哪个列表ESTABLISHED Tcp连接进行分析).

[ServiceContract]
public interface IStreamedService {
    [OperationContract]
    [WebInvoke]
    Stream PullMessage(Stream incomingStream);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false)]
public class MyService : IStreamedService  {

  public System.IO.Stream PullMessage(System.IO.Stream incomingStream) {
       // using(incomingStream) {
       // Read data from stream
       // }

       Stream outgoingStream = // assigned by omitted code;
       return outgoingStream;
  }
Run Code Online (Sandbox Code Playgroud)

服务/绑定的配置

<webHttpBinding>
  <binding name="WebHttpBindingConfiguration" 
           transferMode="Streamed"
           maxReceivedMessageSize="1048576"
           receiveTimeout="00:10:00" 
           sendTimeout="00:10:00"
           closeTimeout="00:10:00"/>
</webHttpBinding>
Run Code Online (Sandbox Code Playgroud)

c# streaming wcf dispose wcf-web-api

23
推荐指数
1
解决办法
1120
查看次数

可移植类库中的System.ComponentModel.DescriptionAttribute

我在枚举中使用Description属性为枚举字段提供用户友好名称.例如

public enum InstallationType
{
    [Description("Forward of Bulk Head")]
    FORWARD = 0,

    [Description("Rear of Bulk Head")]
    REAR = 1,

    [Description("Roof Mounted")]
    ROOF = 2,
}
Run Code Online (Sandbox Code Playgroud)

使用一个很好的帮助方法很容易访问它:

public static string GetDescriptionFromEnumValue(Enum value)
    {
        DescriptionAttribute attribute = value.GetType()
            .GetField(value.ToString())
            .GetCustomAttributes(typeof(DescriptionAttribute), false)
            .SingleOrDefault() as DescriptionAttribute;
        return attribute == null ? value.ToString() : attribute.Description;
    }
Run Code Online (Sandbox Code Playgroud)

我需要将其转换为可移植的类库,但它似乎无法访问System.ComponentModel库.当我尝试添加一个崇敬的VS时告诉我,我已经引用了所有内容.

谢谢

c# dll portable-class-library

23
推荐指数
2
解决办法
9814
查看次数

应用程序域和应用程序池之间的区别?

应用程序域和应用程序池有什么区别?

我读过很多关于这两个术语的文章.但仍然无法正确理解它们.

请用简单的描述详细说明.

谢谢

asp.net application-pool applicationdomain

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

从终结器处理时,只读字段变为空

我有以下课程.现在有时锁定语句会抛出一个ArgumentNullException,在这种情况下,我可以在调试器中看到该disposelock对象实际上是null.

我可以看到处理是错误的,我知道该方法是从Finalizer触发的.

但这怎么可能发生呢?它被定义为只读,并在创建对象时获取其值.

PS:我知道这不是一个好的模式,但它是给定代码的一部分,而我无法解释为什么这个变为null

public abstract class DisposableMarshalByRefObject : MarshalByRefObject, IDisposable
{
    private readonly object disposeLock = new object();


   /// </summary>
   ~DisposableMarshalByRefObject()
   {
       Dispose(false);
   }

   /// <summary>
   /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
   /// </summary>
   public void Dispose()
   {
       Dispose(true);
       GC.SuppressFinalize(this);
   }

   protected void Dispose(bool disposing) //disposing = false,=> finalizer
   {
       lock (disposeLock) //ArgumentNull Exception !
       {
           ....
       }
   }
}           
Run Code Online (Sandbox Code Playgroud)

.net c# garbage-collection

22
推荐指数
2
解决办法
1459
查看次数

为什么HttpWebResponse上没有Dispose方法

HttpWebReponse实现IDisposable接口,但为什么没有Dispose方法.它只包含Close方法.using这个类仍然可以使用模式吗?

.net c# idisposable using-statement

15
推荐指数
1
解决办法
5340
查看次数

获得'语境不是可构建的.添加默认构造函数或提供IDbContextFactory的实现."

我尝试使用代码首次迁移时收到此错误.

我的上下文有一个带有连接名称的构造函数.

public class VeraContext : DbContext, IDbContext
{
    public VeraContext(string NameOrConnectionStringName = "VeraDB")
        : base(NameOrConnectionStringName)
    {
    }

    public IDbSet<User> Users { get; set; }
    public IDbSet<Product> Products { get; set; }
    public IDbSet<IntCat> IntCats { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当项目运行时,此连接名称将使用ninject注入,我也将其指定为默认值,如上面的代码中所示但这没有帮助.

kernel.Bind<IDbContext>()
    .To<VeraContext>()
    .WithConstructorArgument("NameOrConnectionStringName", "VeraDB");
Run Code Online (Sandbox Code Playgroud)

当我尝试使用"启用 - 迁移"添加迁移时会引发错误:

目标上下文'VeraData.EF.Infrastructure.VeraContext'不可构造.添加默认构造函数或提供IDbContextFactory的实现.

如果我从中删除构造函数VeraContext将工作,但创建另一个数据库VeraData.EF.Infrastructure.VeraContext作为其名称.

我假设ninject只在项目运行时传递连接字符串,而不是在我使用代码优先迁移时.无论如何,我可以在使用代码首次迁移时注入/提供连接名称的默认值?

ninject ef-code-first asp.net-mvc-4 ef-migrations entity-framework-5

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

DataGridTemplateColumn中的绑定命令

我使用命令附加到我的ViewModel的View(包含XAML).我需要在单击DataGrid行上的Button时调用命令.我正在使用这种行为(常规指挥有同样的问题).当我单击DataGrid上的按钮时 - 我的命令不会被触发.

为了说明问题 - 我将ListBox放在底部,使用EXACT相同的绑定东西 - 是的,命令有效.因此,它与DataGrid/DataGridTemplateColumn有关

<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding}">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <Button Content="Cancel" >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ei:CallMethodAction MethodName="Cancel" TargetObject="{Binding}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
            </StackPanel>
            <sdk:DataGrid AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding Data}" Grid.Row="1">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Select">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <i:InvokeCommandAction Command="{Binding ElementName=Control, Path=DataContext.ItemSelectedCommand}" CommandParameter="{Binding}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>  
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Binding="{Binding DeviceId}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Device" Width="Auto" FontWeight="Bold" />
                    <sdk:DataGridTextColumn …
Run Code Online (Sandbox Code Playgroud)

silverlight binding datagrid mvvm

13
推荐指数
1
解决办法
6974
查看次数