2017-10-17 129 views
1

我收到以下錯誤。我試圖用Google搜索這個問題。但是,我發現的帖子都沒有幫助過我。參數'名稱'不能爲空,空或只包含空格

編輯: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... 
+0

你確實在使用EDMX?也許去槽屬性窗口,並尋找一個空的名稱(或EntityName,SetName,無論) –

+0

由於表名與類名相同,你不能只是完全省略'表'註釋? – Baksteen

回答

2
at System.ComponentModel.DataAnnotations.Schema.TableAttribute..ctor(String name) 

你沒有張貼代碼的相關部分。這不是關於這個構造函數。

退房TableAttribute Class

你應該尋找項目中的任何[Table][Table("")]

+0

我似乎無法找到.TableAttribute構造函數。 –

+0

@MyreVan你需要看**所有**實體,而不只是你正在查詢的實體。 – DavidG

+0

謝謝@DavidG,其中一個部分在[Table(「」)]中沒有任何內容 –

相關問題