tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why splite FK_Notice in GetParameter

quliting opened this issue · comments

i add list with InsertAsync

the message has a foreign key fk_notice,
GetParameter method the code shows:

var entityPropertyName = propertyName.Split('_').Last();

        IMemberMap propertyMap = map.Properties.SingleOrDefault(p => p.Name == entityPropertyName);
        if (propertyMap == null)
            throw new NullReferenceException(String.Format("{0} was not found for {1}", entityPropertyName, entityType));

my properties don't has Notice property ,so has an exception :

System.NullReferenceException:“Notice was not found for JKY.WDBS.Model.Message”

what should i do ,i just want to add message into db.
thx

Could you send the mapping and how to reproduce the error?

the Message is :

public class Message : BaseModel { [Key] [NotMapped] public int ID { get; set; } public int FK_Notice { get; set; } public int Type { get; set; } public int Status { get; set; } public int FK_User { get; set; } }

` public class BaseModel
{
[Display(Name = "创建时间")]
public DateTime? CreateTime { get; set; }
[Display(Name = "修改时间")]

    public DateTime? ModifyTime { get; set; }
    [Display(Name = "创建人")]

    public int? CreateUser { get; set; }
    [Display(Name = "修改人")]

    public int? ModifyUser { get; set; }
    public string IsValid { get; set; }
}`

i insert MessageList has an error ;

in this dapperExtension:

` public DynamicParameters GetDynamicParameters(T entity, DynamicParameters dynamicParameters, IMemberMap keyColumn, bool useColumnAlias = false)
{
dynamicParameters ??= new DynamicParameters();
foreach (var prop in entity.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.Name != keyColumn.Name))
AddParameter(entity, dynamicParameters, new MemberMap(prop), useColumnAlias);

        return dynamicParameters;
    }`

when i debugger the dapperExtension source code,the prop params is FK_Notice;

then split the FK_Notice,

` IClassMapper map = sqlGenerator.Configuration.GetMap(entityType);
if (map == null)
throw new NullReferenceException(String.Format("Map was not found for {0}", entityType));

        var entityPropertyName = propertyName.Split('_').Last();

        _IMemberMap propertyMap = map.Properties.SingleOrDefault(p => p.Name == entityPropertyName);
        if (propertyMap == null)
            throw new NullReferenceException(String.Format("{0} was not found for {1}", entityPropertyName, entityType));_`

because my Message don't has Notice Property ,so the error occur

@valfrid-ly
are you here

Duplicate from #281