【问题标题】:The argument 'name' cannot be null, empty or contain only white space参数“名称”不能为空、空或仅包含空格
【发布时间】:2017-10-17 14:01:26
【问题描述】:

我收到以下错误。我试着用谷歌搜索这个问题。但是我找到的帖子都没有帮助我。

编辑:根据 Henk 的回复。有问题的表。

[Table("TransactionDetail")]
public partial class TransactionDetail
{
    [Key, Column(Order = 1), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long TransactionDetailId { get; set; }
    public string TransactionName { get; set; }
    public string TransactionValue { get; set; }

    public virtual OriginalTransaction OriginalTrans { get; set; }
}

另一半。

public partial class TransactionDetail
{
    public Transaction trans;
}

更具体地说,当我使用 LINQ“MyContext.SomeDB.Find(x)”时会发生错误。 (如果这有帮助的话)。

我看过的一些似乎适合我的问题但不能帮助我解决的帖子是:

连接字符串:(在 .config 文件中)。

 <add name="TransactionEF" 
 connectionString="some connection string" 
 providerName="System.Data.EntityClient" />

EDMX Connectionstring 'name'

Value cannot be null. Parameter name: source

Getting Error The argument 'nameOrConnectionString' cannot be null, empty or contain only white space with Azure Database

这是我的 dbContext 类。

public partial class TransactionEF : DbContext
{
    public TransactionEF()
        : base("name=TransactionEF")
    {
    }   
    ...
}

System.ArgumentException: The argument 'name' cannot be null, empty or contain only white space.
at System.ComponentModel.DataAnnotations.Schema.TableAttribute..ctor(String name)
at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptor.GetAttributes()
at System.Data.Entity.ModelConfiguration.Utilities.AttributeProvider.GetAttributes(Type type)
at System.Data.Entity.ModelConfiguration.Conventions.TypeAttributeConfigurationConvention`1.<.ctor>b__1(Type t)
at System.Data.Entity.ModelConfiguration.Conventions.TypeConventionWithHavingBase`1.ApplyCore(Type memberInfo, ModelConfiguration modelConfiguration)
at System.Data.Entity.ModelConfiguration.Conventions.TypeConventionBase.Apply(Type memberInfo, ModelConfiguration modelConfiguration)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyModelConfiguration(Type type, ModelConfiguration modelConfiguration)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyModelConfiguration(Type type, ModelConfiguration modelConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EntityType entityType, Func`1 entityTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EntityType entityType, Func`1 entityTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EntityType entityType, Func`1 entityTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EntityType entityType, Func`1 entityTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
at MyCompany... 
at MyCompany... 
at MyCompany... 

【问题讨论】:

  • 您确实在使用 EDMX 吗?也许通过属性窗口寻找一个空的名称(或实体名称、集合名称等)
  • 既然表名和类名一样,那Table这个注解就不能省略了吗?

标签: c# entity-framework


【解决方案1】:
 at System.ComponentModel.DataAnnotations.Schema.TableAttribute..ctor(String name)

您没有发布代码的相关部分。这与这个构造函数无关。

查看TableAttribute Class

您应该在您的项目中查找任何[Table][Table("")]

【讨论】:

  • 我似乎找不到 .TableAttribute 构造函数。
  • @MyreVan 您需要查看所有实体,而不仅仅是您要查询的实体。
  • 感谢@DavidG,其他部分之一在 [Table("")] 中没有任何内容
猜你喜欢
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2020-10-02
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
相关资源
最近更新 更多