Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with C# records' EqualityContract property? #573

Open
zelenij opened this issue May 17, 2022 · 1 comment
Open

How to deal with C# records' EqualityContract property? #573

zelenij opened this issue May 17, 2022 · 1 comment

Comments

@zelenij
Copy link

zelenij commented May 17, 2022

I have a simple C# record, which I want to insert into the database using InsertAsync<> method of SqlKata. The insert fails with the following exception:

 The member p0 of type System.RuntimeType cannot be used as a parameter value

I guess it is caused by the auto-generated EqualityContract property on the record. Is there a workaround for this in SqlKata? I'd rather not fall back to hand-written SQL statements yet.

@rtao
Copy link

rtao commented Aug 9, 2022

Since "EqualityContract" has a type of "Type", should Query just ignore some types internally?

private IEnumerable<KeyValuePair<string, object>> BuildKeyValuePairsFromObject(object data, bool considerKeys = false)
{
var dictionary = new Dictionary<string, object>();
var props = CacheDictionaryProperties.GetOrAdd(data.GetType(), type => type.GetRuntimeProperties().ToArray());
foreach (var property in props)
{
if (property.GetCustomAttribute(typeof(IgnoreAttribute)) != null)
{
continue;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants